Created
July 27, 2016 23:10
-
-
Save joshuathayer/6ff962d659dcdb4b4f644b18509a00e5 to your computer and use it in GitHub Desktop.
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-> | |
[exp t f] | |
`(let [exp-val# ~exp | |
[fn-t# rest-t#] ~(if (seq? t) | |
[(first t) (vec (next t))] | |
[t []]) | |
[fn-f# rest-f#] ~(if (seq? f) | |
[(first f) (vec (next f))] | |
[f []])] | |
(if exp-val# | |
(apply fn-t# (cons exp-val# rest-t#)) | |
(apply fn-f# (cons exp-val# rest-f#))))) | |
(if-> nil | |
(+ 10) | |
(println "is false")) | |
;; "nil is false" | |
(if-> 5 | |
(+ 10) | |
(println "is false")) | |
;; => 15 | |
(if-> 5 | |
inc | |
(println "is false")) | |
;; => 6 | |
(if-> (+ 2 3) | |
inc | |
(println "is false")) | |
;; => 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment