On Dec 17, 9:26 am, "Mark Volkmann" <r.mark.volkm...@gmail.com> wrote:
> On Wed, Dec 17, 2008 at 8:14 AM, Meikel Brandmeyer <m...@kotka.de> wrote:
>
> > Hi,
>
> > On 17 Dez., 14:55, MikeM <michael.messini...@invista.com> wrote:
> >> ((sorted-map 'a 1 'b 2) "a") => ClassCastException
>
> >> I would think that sorted-maps and hash-maps should both give nil for
> >> this, but perhaps the sorted-map implementation requires a cast?
>
> > Obviously a string is not a symbol. A sorted-map only
> > makes sense with comparable keys. How do you compare
> > a string and a symbol for sorting? And indeed:
>
> > ((sorted-map 'a 1 'b 2) 'c) => nil
>
> > I think, that this is a bug - not in sorted-map, but in the user
> > code providing a wrong (type of) key.
>
> I expected that
> ((sorted-map 'a 1 'b 2) "a")
> would return the same result as
> ((sorted-map 'a 1 'b 2) 'c)
>
> In both cases the key isn't in the map, so I thought nil would be returned.
>
One can't determine that a key isn't in a sorted map without comparing
it to other keys. Thus, unless you supply your own Comparator (using
sorted-map-by), it is subject to the contract of Comparable, which
specifies ClassCastException on type mismatch.
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
-~----------~----~----~----~------~----~------~--~---