Clojure

Fix defrecord keyword lookup on fields matching no-arg methods

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: Release 1.2
  • Component/s: None
  • Labels:
    None

Description

Current behaviour:

user=> (defrecord Foo [size seq])
user.Foo
user=> (:size (Foo. 42 :b))
2
user=> (:seq (Foo. 42 :b))
([:size 42]
 [:seq :b])

Patch attached, with a test. Thoughts:

1. filtering on base-fields would probably be cleaner, but it looks like (class ~'gtarget) isn't fully formed at that point?
2. this results in a .valAt lookup for any fields that collide with no-arg methods implemented by the defrecord's class. That's unavoidable AFAICT.
3. The best solution would be to disambiguate field access vs. no-arg method invocation, i.e. have a variant of (. obj field) that would be specifically for field access (which is very occasionally needed elsewhere as well). This would nullify # 2.

Activity

Hide
Assembla Importer added a comment -

richhickey said: (In [[r:762d1531b6440722d5d1c0dfee4776d99289385e]]) Fix defrecord keyword lookup on fields matching no-arg methods, fixes #329

Branch: master

Show
Assembla Importer added a comment - richhickey said: (In [[r:762d1531b6440722d5d1c0dfee4776d99289385e]]) Fix defrecord keyword lookup on fields matching no-arg methods, fixes #329 Branch: master

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: