Skip to content

Instantly share code, notes, and snippets.

@athos
Created March 31, 2011 03:08
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 athos/895752 to your computer and use it in GitHub Desktop.
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)
(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