Last active
December 20, 2016 15:33
-
-
Save HakimCassimallyBBC/dbd46fe288cfeacbb3db5259dd898b48 to your computer and use it in GitHub Desktop.
curry macro attempt
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
(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