Skip to content

Instantly share code, notes, and snippets.

@gfredericks
Created June 27, 2011 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gfredericks/1048931 to your computer and use it in GitHub Desktop.
Save gfredericks/1048931 to your computer and use it in GitHub Desktop.
;; 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