Created
March 31, 2011 03:08
-
-
Save athos/895752 to your computer and use it in GitHub Desktop.
an idea of alternative macros for letfn (I hate its too deep indents)
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
(letfn [(kons [x y] | |
(cons x y))] | |
(kons 1 nil)) | |
(defmacro letfn1 [name args & form] | |
(let [fbody (butlast form) | |
body (last form)] | |
`(letfn [(~name ~args ~@fbody)] | |
~body))) | |
(letfn1 kons [x y] | |
(cons x y) | |
(kons 1 nil)) | |
(defmacro local-defns [& forms] | |
(let [[defns body] (split-with #(= (first %) 'defn) forms)] | |
`(letfn ~(vec (for [[_ name args & fbody] defns] | |
`(~name ~args ~@fbody))) | |
~@body))) | |
(local-defns | |
(defn kons [x y] | |
(cons x y)) | |
(kons 1 nil)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment