letfn assumes fnspecs are all already properly shaped, like: (fn-name
[args] body)
But it is possible that a macroexpansion is needed to get them in the right
shape before letfn does its work, especially if the user found all his
fnspecs were of similar shape and used a macro to eliminate boilerplate
repetition. His fnspecs would be (name-of-macro macro-args) and would
expand to (fn-name [args] body)
Original:
(defmacro letfn
"fnspec ==> (fname [params*] exprs) or (fname ([params*] exprs)+)
Takes a vector of function specs and a body, and generates a set of
bindings of functions to their names. All of the names are available
in all of the definitions of the functions, as well as the body."
{:added "1.0", :forms '[(letfn [fnspecs*] exprs*)],
:special-form true, :url nil}
[fnspecs & body]
`(letfn* ~(vec (interleave (map first fnspecs)
(map #(cons `fn %) fnspecs)))
~@body))
Macro-friendly wrapper:
(defmacro letfn'
[fnspecs & body]
`(letfn ~(vec (map macroexpand fnspecs)) ~body))
1. What do you think?
2. Is the user I mentioned above using macros wisely (use case is to
eliminate boilerplate code)?
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.