Created
October 14, 2014 04:31
-
-
Save ericnormand/1be875342e40f95ac3dc to your computer and use it in GitHub Desktop.
Who needs conditionals in Clojure?
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
(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