Thanks for that recommendation, I definitely like that proposal!
I guess the drawback is then that destructuring will not be "safe".
I have to think some more time about it.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send e
On Tue, Apr 26, 2011 at 1:06 PM, Steve Miner wrote:
> Creating your own "Closed Map" type would be the object-oriented approach.
> One downside is that a closed-map feels like a normal map, but can't be
> safely substituted for most maps because of the booby-trap when using assoc
> (etc.) with
Creating your own "Closed Map" type would be the object-oriented approach. One
downside is that a closed-map feels like a normal map, but can't be safely
substituted for most maps because of the booby-trap when using assoc (etc.)
with a new key. It doesn't really fulfill the map contract anymo
This project seems to be all about beans, but it is empty so far:
https://github.com/clojure/java.data
On Apr 23, 8:57 am, Christian Schuhegger
wrote:
> Thanks for all of your answers, but I think for my use cases the
> approach proposed by Justin looks most promising. I'll implement my
> own clo
Thanks for all of your answers, but I think for my use cases the
approach proposed by Justin looks most promising. I'll implement my
own closed map.
Another idea that come to my mind was that a closed map is actually a
Java Bean without behaviour. Perhaps the closed map could be
implemented by dyn
This defrecord2 implementation has key checks on construction but
still allows you to forcibly insert other keys after the fact. I
believe the proposed defrecord enhancements for 1.3 may have some
similar opportunities. You could use your own assoc that checked the
known record keys too.
https:/
With regard to mistyped keys in general, a simple option is to use
named keys; then the compiler will flag undefined ones.
(def k :key)
...
(k m)
On Apr 21, 10:44 pm, Christian Schuhegger
wrote:
> I am taking up a discussion from
> 2010:https://groups.google.com/group/clojure/browse_frm/thread/6
I should be straightforward to implement a closed map (or record)
yourself using deftype. It could implement all the same interfaces as
Clojure's built-in maps, ensuring compatibility with assoc and such.
Here's an example of a map variant implemented using deftype:
https://github.com/clojure/cloj
I am taking up a discussion from 2010:
https://groups.google.com/group/clojure/browse_frm/thread/60dff89149c3d2e6/
I would prefer if it would be possible to define "closed maps", e.g.
maps that allow only a certain set of keywords, both for get and
"set" (like in assoc, assoc-in, update-in, ...).