Created
March 9, 2010 14:11
-
-
Save pervognsen/326606 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
;; improved version from chouser | |
(defmacro named [kwargs defaults & body] | |
`(let [{:keys [~@(take-nth 2 defaults)] :or ~(apply array-map defaults)} | |
(apply array-map ~kwargs)] | |
~@body)) | |
;; Example | |
(defn draw [x & args] | |
(named args [size 42 | |
color :blue] | |
(print "draw" size color))) | |
(draw []) ;; => draw 42 :blue | |
(draw [] :size 666) ;; => draw 666 :blue | |
(draw [] :color :red) ;; => draw 42 :red | |
(draw [] :size 666 :color :red) ;; => draw 666 :red | |
(draw [] :color :red :size 666) ;; => draw 666 :red |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment