On Fri, Mar 11, 2011 at 11:12 PM, Armando Blancas <armando_blan...@yahoo.com> wrote: > You need to quote the vector so the date will be created inside eval, > instead of having the date go into eval as an element of the > (evaluated) vector.
A more interesting question is "why does this error exist in the first place"? Why doesn't eval (or macro expansion) accept general objects in the input rather than just a few specific types (strings, numbers, keywords, lists, sets, maps, vectors, etc.)? There are use cases where it would be quite convenient if all objects that presently produced that error were instead self-evaluating in the manner of numbers, strings, and keywords. For one thing, as an optimization you could precompute some expensive-to-construct object and directly embed it in compiled code instead of having to calculate it at runtime, or muck about with computing it, saving it out to a file, reading it on startup, and adding all the file and directory configuration options that start to be needed as soon as your app has external data files it depends on. Possibly-related (and sometimes equally inconvenient) is that actual compiled Clojure function objects do *not* produce that error, and work if they are not closures, but produce cryptic errors when subsequently invoked if they *are* closures, as though they got copied without the closed-over values or something instead of just embedded directly. Here is the weird behavior of function objects in eval (same result in macro expansions, when the macro-generated code is actually run): user=> (def f (let [x 10] (fn [] x))) ; f is a closure #'user/f user=> (f) ; works when directly called at repl 10 user=> (eval '((let [x 10] (fn [] x)))) ; create the closure and call it inside eval -- works 10 user=> (eval f) ; eval the closure itself -- returns the function object #<user$fn__1429$fn__1430 user$fn__1429$fn__1430@123b9c1> user=> (eval '(f)) ; eval can call the function through its var, and it works 10 user=> (eval `(~f)) ; eval calling the closure directly embedded in the call expression -- weird exception #<CompilerException java.lang.ExceptionInInitializerError (NO_SOURCE_FILE:40)> user=> (def f (fn [] 10)) ; replace f with a non-closure function with the same return value #'user/f user=> (eval `(~f)) ; eval calling the function directly embedded in the call expression -- works! 10 user=> -- 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