Skip to content

Instantly share code, notes, and snippets.

@ericnormand
Created October 14, 2014 04:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericnormand/1be875342e40f95ac3dc to your computer and use it in GitHub Desktop.
Save ericnormand/1be875342e40f95ac3dc to your computer and use it in GitHub Desktop.
Who needs conditionals in Clojure?
(defn- truth [then else] (then))
(defn- falsehood [then else] (else))
(def boolness {false falsehood nil falsehood})
(defn if* [condition then-fn else-fn]
((get boolness condition truth) then-fn else-fn))
(defmacro my-if [test then else]
`(if* ~test (fn [] ~then) (fn [] ~else)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment