Skip to content

Instantly share code, notes, and snippets.

@joshuathayer
Created July 27, 2016 23:10
Show Gist options
  • Save joshuathayer/6ff962d659dcdb4b4f644b18509a00e5 to your computer and use it in GitHub Desktop.
Save joshuathayer/6ff962d659dcdb4b4f644b18509a00e5 to your computer and use it in GitHub Desktop.
(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