[CLJ-1199] Record values are not 'eval'uated, unlike values of PersistentMap: Created: 13/Apr/13 Updated: 02/Aug/15 Resolved: 02/Aug/15
|Affects Version/s:||Release 1.5|
I'm not sure if this is by design, but it caught me off guard.
user> (defrecord A [x])
user> (eval (hash-map :x `long))
and in case it matters, here's a simplified version of the real use case where this came up, with no eval – just a macro:
user> (defmacro munge-meta1 [x] (assoc x :schema (->A (:schema (meta x)))))
user> (defmacro munge-meta2 [x] (assoc x :schema (hash-map :x (:schema (meta x)))))
This seems to be fixed by moving the record creation post-evaluation, so it's not a big deal, just surprising (plus I haven't yet convinced myself that this will always work if the user's schema itself contains record-creating forms, although it seems to work OK):
user> (defmacro munge-meta1 [x] (assoc x :schema `(->A ~(:schema (meta x)))))
I brought this up on the mailing list here:
|Comment by Alex Miller [ 02/Aug/15 8:18 PM ]|
This is by design, see http://clojure.org/datatypes - "each element in the vector form is passed to the deftype/defrecord's constructor un-evaluated"