Last active
August 29, 2015 13:57
-
-
Save patrickgombert/9521780 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 with-defaults [defaults definition] | |
(let [function-name (first definition) | |
arguments (second definition) | |
argument-subset (vec (nthrest arguments (count defaults))) | |
body (rest (rest definition))] | |
`(defn ~function-name | |
(~argument-subset | |
(~function-name ~@(reverse (concat argument-subset defaults)))) | |
(~arguments | |
~@definition)))) | |
(with-defaults [1] (show-args [a b] (str a ", " b))) | |
(show-args 2) ; => 1, 2 | |
(show-args 3 4) ; => 3, 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment