Skip to content

Instantly share code, notes, and snippets.

@patrickgombert
Last active August 29, 2015 13:57
Show Gist options
  • Save patrickgombert/9521780 to your computer and use it in GitHub Desktop.
Save patrickgombert/9521780 to your computer and use it in GitHub Desktop.
(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