On Mar 8, 2009, at 9:13 PM, Shawn Hoover wrote:
Close... you can assoc new keys into a struct instance, but you can't dissoc any of the basis keys.
That's right. Given: user=> (defstruct foo :a :b) #'user/foo user=> (def t (struct foo 3)) #'user/t dissoc of a basis key throws an exception: user=> (dissoc t :a) java.lang.Exception: Can't remove struct key (NO_SOURCE_FILE:0)I wonder if it's important to throw in this case or if it would be more in keeping with the description:
"struct maps act just like maps, except they store their basis keys efficiently"
if dissoc would associate nil ("nothing") with the key instead: user=> (dissoc t :a) {:a nil, :b nil}Doing so would make the value associated with :a become the same as if it had never been initialized, just like :b in this case.
Perhaps the choice between an exception and assoc'ing "nothing" comes down to the distinction between:
"dissoc means remove this key from this map" (where throwing an exception is clearly correct), and "dissoc means remove any value associated with this key from this map" (where assoc'ing nil might be preferable). --Steve
smime.p7s
Description: S/MIME cryptographic signature