Skip to content

Instantly share code, notes, and snippets.

@athos

athos/gist:895752

Created Mar 31, 2011
Embed
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)]
~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
You can’t perform that action at this time.