Clojure

eval of defrecord instance with no fields produces {}, not itself

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Duplicate
  • Affects Version/s: Release 1.5
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:
    Mac OS X Clojure 1.5.1

Description

user> (defrecord Foo [])
user.Foo
user> (Foo.)
#user.Foo{}
user> (eval (Foo.))
{}

user> (defrecord Foo [a b])
user.Foo
user> (eval (Foo. 1 2))
#user.Foo{:a 1, :b 2}

As you can see, evaluating the record with no fields loses the type information. This came up in code that uses records to describe argument schema information for functions in a macro, with no direct use of 'eval'. It is unexpected because of the inconsistency between empty and non-empty defrecords, and because the Clojure docs say 'Any object other than those discussed above will evaluate to itself.'

http://clojure.org/evaluation

I'm happy to elaborate on the use case if there are questions.

Activity

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: