Skip to content

Instantly share code, notes, and snippets.

@Jared-Prime
Created July 3, 2012 01:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jared-Prime/3036783 to your computer and use it in GitHub Desktop.
Save Jared-Prime/3036783 to your computer and use it in GitHub Desktop.
MadClojure - macros demo July 1
(ns my.namespace.core)
(if true 1)
(gensym)
(defn my-when [pred & body]
(let [x# pred]
`(if ~x# (do ~@body (println "done")))))
(defn my-when2 [pred & body]
(list 'if pred (list* 'do body)))
(macroexpand-1 `(my-when2 true (+ 1 1)))
(apply my-when2 `(true
(println 1)
(println 2)))
(if true
(do (println 1)
(println 2)))
(defmacro f [x]
`(inc ~x))
(map f [1 2 3 4 ])
(some #(= `blah %)
(flatten `(defmacro blah [f & body]
(+ 1 x))))
(defmacro aprog1 [res & body]
`(let [~'it ~res]
~@body
~'it))
(aprog1 "aprog1" (println (str "omg" it "is a macro")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment