On Jun 27, 11:32 am, Meikel Brandmeyer <m...@kotka.de> wrote:
> Am 26.06.2009 um 23:44 schrieb Michael Spiegel:
> > =>(def foo (sorted-set "bob" "alice" "michael"))
> > => (contains? foo 5)
> > java.lang.ClassCastException: java.lang.String cannot be cast to  
> > java.lang.Number (NO_SOURCE_FILE:0)
>
> IIRC, this came up already. And the general result was,
> that it is a bug in the user code to compare an Integer
> with a String.
>
> A sorted-set is not a usual set. It contains elements,
> which can be sorted according to an ordering.
> Comparing two things, where one is not in the domain
> of the ordering, is not defined.

I'd agree that a ClassCastException is not inappropriate if you try to
put heterogeneous objects into a sorted-set.

But contains? should probably just return true or false, never throw.
Michael's set doesn't contain 5; asking whether it does does not seem
to me to be an error. I think it would be desirable for contains? to
have returned false. A simple, crude way to make it do so would be to
wrap the original contains? code in a try ... catch that catches
ClassCastException and returns false if one gets thrown.

--~--~---------~--~----~------------~-------~--~----~
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
Note that posts from new members are moderated - please be patient with your 
first post.
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