Problems:
- completeness and consistency: need to be able to read and write records like other Clojure types
- dynamism: need to create defrecords without class-in-hand. Performantly, of course
- convenience: want map-like construction instead of positional slotwise construction
Open questions:
- modularity friendliness
- multimethods are a poor fit
- need to have a map that we can clear entries from later
- keep a weak ref to the entire block of code that instantiates objects
- tested this at the REPL and it works fine
- instead of a multimethod for records:
recordkeeps a ConcurrentHashMap of keywords => (weak-ref instantiating-fn)- every update to the map walks the queue and clears dead entries
- similar to the way Clojure handles keywords today
- multimethods are a poor fit
- print/read syntax
- for now, use
#=(record ...) - caveat: forces people to allow arbitrary execution in order to deserialize records
- Rich: is there some way to open record instantiation without opening arbitrary execution?
- for now, use
- fn/macro/both?
- both
- need macro for metadata from reader
- one fn, or fn-per-record?
- one fn
- otherwise you get namespace issues and name pollution
Note: the resolutions of these questions imply two significant changes to Stu's ancient patch
- weakref map instead of multimethod
- macro in addition to fn form
Tickets:
Some (non-contributed) code that demonstrates people's need for this:
- cemerick's defrecord slot defaults
- David McNeil's enhanced clojure records
Labels: