Skip to content

Instantly share code, notes, and snippets.



Created Mar 31, 2011
What would you like to do?
an idea of alternative macros for letfn (I hate its too deep indents)
(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)]
(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)))
(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
You can’t perform that action at this time.