On Mon, Oct 15, 2012 at 8:11 PM, Lee Spector <lspec...@hampshire.edu> wrote: > On Oct 15, 2012, at 12:51 PM, Alan Malloy wrote: > >> Evaluating function literals is not intended to work; that it works >> for non-closure functions should be treated as a coincidence. > > Really? Eval "Evaluates the form data structure (not text!) and returns the > result." Why would certain things like function literals be excluded? IMHO > they shouldn't be, and in fact I've built some code around dynamically > constructed and evaluated function literals.
I think you're confusing: (eval (list '(fn [x] x) 1)) with: (eval (list (fn [x] x) 1)) In both cases, eval is being passed a list of two items. The first element of the list differs, however: In the first case, it is a list beginning with the special form fn: a function literal that has not yet been evaluated. Eval will have no trouble with this. In the second case it is a reference to an object implementing the clojure.lang.IFn interface. That's not a function literal, it's the result of evaluating one. This, as you've discovered, may or may not work with eval. If the distinction I'm trying to make is not clear to you, I'd suggest having a look at http://www.infoq.com/presentations/Clojure-Macros (It does a good job exploring these kinds of distinctions as it's vital to have an accurate mental model of how Clojure is evaluated if one intends to write macros.) // ben -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en