Skip to content

Instantly share code, notes, and snippets.

@HakimCassimallyBBC
Last active December 20, 2016 15:33
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 HakimCassimallyBBC/dbd46fe288cfeacbb3db5259dd898b48 to your computer and use it in GitHub Desktop.
Save HakimCassimallyBBC/dbd46fe288cfeacbb3db5259dd898b48 to your computer and use it in GitHub Desktop.
curry macro attempt
(defmacro curry [fname fixed-args & body]
(let [arg-count (count fixed-args)]
`(defn ~fname [& ~'args]
(cond
(< (count ~'args) ~arg-count)
(apply partial (concat [~fname] ~'args))
:else
(let [~fixed-args ~'args]
~@body)))))
(curry foo [a b] (+ a b))
(foo 1 2)
;; 3
((foo 1) 2)
;; 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment