Clojure

Add record? predicate

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: Release 1.6
  • Component/s: None
  • Labels:
  • Patch:
    Code and Test
  • Approval:
    Ok

Description

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.Foo
user=> (def f (->Foo 1))
#'user/f
user=> (record? f)
true

Screened by: Alex Miller

Activity

Hide
Alex Miller added a comment -

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

Show
Alex Miller added a comment - Added new patch that contains only the record? fn and omits the type stuff. Marking Screened again.
Hide
Alex Miller added a comment -

Added updated patch that just adds record?

Show
Alex Miller added a comment - Added updated patch that just adds record?
Hide
Alex Miller added a comment -

Altering title and description per Rich's comment.

Show
Alex Miller added a comment - Altering title and description per Rich's comment.
Hide
Rich Hickey added a comment -

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

Show
Rich Hickey added a comment - I think this should do record? only. type? conveys no semantics, and the things are not types themselves.
Hide
Alex Miller added a comment -

Tweaked patch to say added in 1.6, not 1.5.

Show
Alex Miller added a comment - Tweaked patch to say added in 1.6, not 1.5.
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.
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))
Hide
Assembla Importer added a comment -
Show
Assembla Importer added a comment - Converted from http://www.assembla.com/spaces/clojure/tickets/394

People

Vote (0)
Watch (4)

Dates

  • Created:
    Updated:
    Resolved: