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

Hide
Nicola Mometto added a comment -

I think this is a duplicate of http://dev.clojure.org/jira/browse/CLJ-1093

Show
Nicola Mometto added a comment - I think this is a duplicate of http://dev.clojure.org/jira/browse/CLJ-1093
Hide
Jason Wolfe added a comment -

You are right, sorry for the duplication. I searched for empty record in JIRA and somehow missed that ticket.

Show
Jason Wolfe added a comment - You are right, sorry for the duplication. I searched for empty record in JIRA and somehow missed that ticket.
Hide
Andy Fingerhut added a comment -

Close as duplicate of CLJ-1093.

Show
Andy Fingerhut added a comment - Close as duplicate of CLJ-1093.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: