On Mar 8, 10:10 pm, "Stephen C. Gilardi" <squee...@mac.com> wrote:
> 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).
>

dissoc definitely means the former. A mapping to nil is not no
mapping.

(contains? (dissoc m k) k) -> false

Rich

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to