Tiago Antão a écrit :

> Just a question about the consistency of the API:
> When one passes a "strange" (ie, wrong type) object to contains?, say
> (contains? 'blab 'a)
> the result is a false.
> But if  one passes the wrong type to, e.g., even?, like
> (even? 'a)
> The result is:
> java.lang.ClassCastException: clojure.lang.Symbol cannot be cast to
> java.lang.Number (NO_SOURCE_FILE:0)
> 
> This seems a bit inconsistent, in the sense that one would expect the
> same behavior for the same kind of error.

Is it really the same kind of error? I am not sure. In fact, I'd say 
this depends on the precise definitions of the two predicates.

The behaviour of contains? makes sense if you define "a contains b" as 
"a is a collection AND b is an element of a". This definition implies a 
return value of false whenever a is not a collection.

In the same spirit, one could define "x is even" as "x is an integer AND 
x mod 2 = 0", concluding that (even? 'a) should return false because 'a 
is not an integer. But that definition has its weak points as well, e.g. 
that even? and odd? are not complementary.

I don't think it is possible to define a perfectly coherent set of 
definitions of everything in the Clojure API that satisfies 
simultaneously all conditions that one might expect to hold. In the end 
it's a matter of priorities, and Rich's choices for Clojure are mostly 
in the "pragmatic" category: a compromise between principles, 
simplicity, and efficiency.

Konrad.


__________ Information provenant d'ESET NOD32 Antivirus, version de la base des 
signatures de virus 4589 (20091109) __________

Le message a été vérifié par ESET NOD32 Antivirus.

http://www.eset.com



--~--~---------~--~----~------------~-------~--~----~
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