On Sun, 2011-12-18 at 11:56 -0800, Bill Robertson wrote:
> I'm trying to define records based on meta data read in at runtime,
> Short of generating a string and calling eval on it, is this possible?

Supposing by "string" you meant "expression", no.

https://groups.google.com/d/msg/clojure/kdAWhfBbxVc/czQ7rPRQwPsJ

You may wish, however, to generate your defrecord forms in a macro
instead.  At that point, you may exploit the fact that previous
top-level forms have already been evaluated at macro-expansion time:

(defmacro my-stuff [blah]
  ;; I can assume that (hey you!) has been evaluated!
  ;; So if (hey you!) put something where I can get at it,
  `(defrecord ~based-on-hey-you ~@based-on...))

(hey you!)

(my-stuff that-relies-on-hey-you)

Remember, though, that if you AOT-compile, your generated defrecord will
be based on the (hey you!) that was evaluated when compiling, not the
one evaluated when loading the compiled files later.  In short, my-stuff
should have deterministic, repeatable results, and should therefore only
rely on deterministic features of (hey you!), e.g. gensyms will break.

-- 
Stephen Compall
^aCollection allSatisfy: [:each|aCondition]: less is better

-- 
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

Reply via email to