<< Back to previous view

[CLJ-394] Add record? predicate Created: 05/Jul/10  Updated: 11/Jan/14  Resolved: 11/Jan/14

Status: Closed
Project: Clojure
Component/s: None
Affects Version/s: None
Fix Version/s: Release 1.6

Type: Enhancement Priority: Minor
Reporter: Assembla Importer Assignee: Unassigned
Resolution: Completed Votes: 0
Labels: defrecord

Attachments: File clj-394-add-predicate-for-record-3.diff     File clj-394-add-predicates-for-type-and-record-2.diff     File clj-394-add-predicates-for-type-and-record.diff    
Patch: Code and Test
Approval: Ok


Would like a predicate that can be used to check whether an object is an instance of a defrecord.

Patch: clj-394-add-predicate-for-record-3.diff

Approach: Use existing marker interface IRecord to add new record? predicate.

user=> (defrecord Foo [x])
user=> (def f (->Foo 1))
user=> (record? f)

Screened by: Alex Miller

Comment by Assembla Importer [ 24/Aug/10 12:04 AM ]

Converted from http://www.assembla.com/spaces/clojure/tickets/394

Comment by Steve Miner [ 20/Apr/12 1:55 PM ]

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

Comment by Devin Walters [ 20/Oct/12 6:38 PM ]

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.

Comment by Alex Miller [ 16/Oct/13 9:29 AM ]

Tweaked patch to say added in 1.6, not 1.5.

Comment by Rich Hickey [ 22/Nov/13 11:41 AM ]

I think this should do record? only. type? conveys no semantics, and the things are not types themselves.

Comment by Alex Miller [ 22/Nov/13 12:39 PM ]

Altering title and description per Rich's comment.

Comment by Alex Miller [ 22/Nov/13 12:49 PM ]

Added updated patch that just adds record?

Comment by Alex Miller [ 22/Nov/13 12:53 PM ]

Added new patch that contains only the record? fn and omits the type stuff. Marking Screened again.

Generated at Fri Jan 19 15:59:42 CST 2018 using JIRA 4.4#649-r158309.