Created
June 27, 2011 14:13
-
-
Save gfredericks/1048931 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
;; this should let you do something like | |
;; | |
;; (defn foobar | |
;; [x y z] | |
;; (with-defaults | |
;; [x (even? x) 1881 | |
;; y (odd? y) 823] | |
;; (+ x y z))) | |
;; | |
(defmacro with-defaults | |
[triples & body] | |
(let [lettings | |
(mapcat | |
(fn [[arg-name validity default]] | |
(list arg-name (list 'if validity arg-name default))) | |
(partition 3 triples))] | |
`(let [~@lettings] ~@body))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment