Skip to content

Instantly share code, notes, and snippets.

@deadghost
Created November 29, 2016 08:04
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 deadghost/4233666bc6b77ce028c8843b2d60f221 to your computer and use it in GitHub Desktop.
Save deadghost/4233666bc6b77ce028c8843b2d60f221 to your computer and use it in GitHub Desktop.
Lisp macro example - writing if in terms of cond
(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