Clojure

defrecord factory inaccessibly from within type implementation

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: Release 1.4
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Patch:
    Code
  • Approval:
    Ok

Description

Discovered this issue working through https://github.com/relevance/labrepl when trying to use the new factory sytax for records:

(defprotocol Player
(choose [p])
(update-strategy [p me you]))

(defrecord Mean [last-winner]
  Player
  (choose [_] (if last-winner last-winner (random-choice)))
  (update-strategy [_ me you] (->Mean (when (iwon? me you) me))))

Notice that Mean returns a new instance with a different strategy. However, the factory methods are not defined until after the record has been created thus this results in a syntax error. To fix this I updated the macro to declare the factory methods before the record is emitted.

Activity

Hide
Kevin Downey added a comment -

looks good to me

Show
Kevin Downey added a comment - looks good to me
Hide
Aaron Bedra added a comment -

Screened against e58a87fac72ed4b84a1d92f1e455b92d7ed3ef39

Show
Aaron Bedra added a comment - Screened against e58a87fac72ed4b84a1d92f1e455b92d7ed3ef39

People

Vote (4)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: