Clojure

Add marker Interfaces for defrecords and deftypes plus boolean test fns

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: Release 1.6
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code and Test

Description

Sometimes one would like to know if an object is an instance of a deftype or a defrecord.
Add (possibly empty) marker Interfaces that allow an efficient test, plus test fns
'record?' and 'deftype?'.

Activity

Hide
Assembla Importer added a comment -
Show
Assembla Importer added a comment - Converted from http://www.assembla.com/spaces/clojure/tickets/394
Rich Hickey made changes -
Field Original Value New Value
Fix Version/s Release 1.4 [ 10040 ]
Fix Version/s Backlog [ 10035 ]
Reporter Assembla Importer [ importer ]
Priority Blocker [ 1 ]
Rich Hickey made changes -
Priority Blocker [ 1 ] Minor [ 4 ]
Hide
Steve Miner added a comment -

As of Clojure 1.3, there are marker interfaces named clojure.lang.IType and clojure.lang.IRecord. You can use instance? with those interfaces. I'm not sure if they're actually documented for public use, but they seem to work as expected in 1.3 and 1.4. If you want record?, you can try this:

(defn record? [rec] (instance? clojure.lang.IRecord rec))

Show
Steve Miner added a comment - As of Clojure 1.3, there are marker interfaces named clojure.lang.IType and clojure.lang.IRecord. You can use instance? with those interfaces. I'm not sure if they're actually documented for public use, but they seem to work as expected in 1.3 and 1.4. If you want record?, you can try this: (defn record? [rec] (instance? clojure.lang.IRecord rec))
Christopher Redinger made changes -
Fix Version/s Release 1.4 [ 10040 ]
Fix Version/s Release 1.5 [ 10150 ]
Hide
Devin Walters added a comment -

See attached code and test. I'm unsure as to whether or not the location of the tests and predicates make sense. Please let me know if I should move them elsewhere.

Show
Devin Walters added a comment - See attached code and test. I'm unsure as to whether or not the location of the tests and predicates make sense. Please let me know if I should move them elsewhere.
Devin Walters made changes -
Patch Code and Test [ 10002 ]
Attachment clj-394-add-predicates-for-type-and-record.diff [ 11590 ]
Stuart Halloway made changes -
Fix Version/s Release 1.5 [ 10150 ]
Fix Version/s Release 1.6 [ 10157 ]

People

Vote (0)
Watch (4)

Dates

  • Created:
    Updated: