On Fri, Feb 14, 2014 at 9:41 PM, Mars0i <marsh...@logical.net> wrote:

> Could someone clarify for me why "some?" as a name for not nil makes sense
> at all in the first place?  Not criticizing.  I just don't understand what
> existence or there being some of something has to do with nil.
>

nil is often used to indicate that a value is not present.
For example:
(get {:a 1 :b 2} :c) -> nil
nil is also returned by seq to indicate that the collection is empty and
therefore doesn't have a first and rest.
So I think the reasoning is that you are asking if the result is
"something" versus "nothing".  In other words, some? is essentially a
short-form of the name "something?".

Coming to Clojure from Scheme, I've always thought it quirky that Clojure
has two distinct falsey values, false and nil.  I remember a thread in the
early days of Clojure in which it was explained to me that this was a
common idiom in Common Lisp, and was included in Clojure primarily to
enable the pattern:
(when (seq s) ...)

It also enabled a lot of idioms that *almost* work, but can bite you if
you're not careful, for example (filter identity ...) to strip out nil
values (but oops, you didn't mean for it to also strip out false values).
These sorts of things are a fairly common source of bugs, because it can
often be hard to reason about whether you care about a value being truthy,
falsey, not false, false, not nil, or nil, and determine exactly what
promises are made by library predicates you are using.  So what we see now
is the proliferation of variations on the core constructs that care
specifically about non-nil values rather than truthy values, because it
turns out that in a lot of cases you really just want to get rid of or
detect nil values but not false.  This trend started with keep and
keep-indexed, then grew to some-> and some->>, and now the newest additions.

I agree that it is very confusing that "some" searches for the first truthy
value, but some-> and some->> only care about non-nil values.  The new
names are clearly modeled after the some-> and some->> functions, but that
just makes the behavior of the original "some" even more of a glaring
outlier.

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to