Created
November 29, 2016 08:04
-
-
Save deadghost/4233666bc6b77ce028c8843b2d60f221 to your computer and use it in GitHub Desktop.
Lisp macro example - writing if in terms of cond
This file contains 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
(defmacro if-macro [pred truth-body false-body] | |
(cond | |
pred truth-body | |
:else false-body)) | |
(defn if-fn [pred truth-body false-body] | |
(cond | |
pred truth-body | |
:else false-body)) | |
(if-macro (= 1 1) | |
"tis true" | |
(print "tis false")) | |
;;=> "tis true" | |
(if-fn (= 1 1) | |
"tis true" | |
(print "tis false")) | |
;;=> tis false | |
;; "tis true" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment