Clojure avoid as much as possible making nil or emptiness a special case
requiring the caller to test it before calling a function.

I would like this to remain like that after years of testing null in Java before
doing anything else on a object to prevent exceptions.

This is a design decision taken years ago. If you really need to test emptiness,
empty? exists exactly for this purpose.

Luc


> Right now
> 
> (last []) => nil
> (last [nil]) => nil
> 
> So there is no way to differentiate these two (except with some
> emptiness checking). In my opinion (last []) should throw an
> exception, because that's when last does not apply. From another point
> of view, there are two cases:
> 
> 1. The local semantics requires the collection not to be empty.
> Throwing an exception here will remove the burden of manual checking.
> 
> 2. The local semantics allows the collection to be empty, in that case
> the caller needs to do
> (when-not (empty? c) (last c)).
> 
> case 1 is the "normal case" with higher probability, so the burden of
> checking should be on the second case.
> 
> Your opinion?
> 
> Note this is rather academic because it probably is too late do
> anything about it at this stage. But it may help future cases.
> 
> -- 
> 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
> 
--
Softaddicts<lprefonta...@softaddicts.ca> sent by ibisMail from my ipad!

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