Created
July 3, 2012 01:07
-
-
Save Jared-Prime/3036783 to your computer and use it in GitHub Desktop.
MadClojure - macros demo July 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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