Every/every? vs some/some?

I found it a bit confusing that every? and some take a predicate, but some? does not.

(every? oddp some-integers)
(some oddp  some-integers)
(some? some-booleans)

In general, while it is possible with some digging through several-year-old Clojure Google group posts to look for rationale on names, including people who dislike or disagree with the names chosen, there is a small core team of folks who design Clojure and the names used, and they make the decisions on that.

Some of those Google group messages might or might not give you reasons that you are satisfied with, but I am not sure if that is what you are looking for here. I am not aware of any collected reference of “here is the detailed rationale of how everything in Clojure was designed” (and if it were public, I am pretty sure I would know about it).

There is a book “Clojure: The Essential Reference” by Renzo Borgatti that contains lots of details about Clojure internals, but none of the designers of Clojure are authors, so how much any rationale it might provide on why things are the way they are must be judged with that qualification.

2 Likes

It might help to look at it this way: every? and some? are both predicates in their own right, whereas some is a search or computation function over seqs.

Andy is right that these names have a looooong history and that bikeshedding them has gotten a bit old, especially to some of the core team. It is what it is.

1 Like

A core function whose name ends with ? is going to return strictly true/false so this might be a helpful comparison of those functions:

user=> (every? odd? [1 2 3])
false
user=> (every? odd? [2 4 6])
false
user=> (every? odd? [1 3 5])
true
user=> (some odd? [1 2 3])
true
user=> (some odd? [2 4 6])
nil
user=> (some odd? [1 3 5])
true

some returns the first truthy result of applying the predicate to each element so it will return the result of (odd? n) for the first odd number. If there are no odd numbers, it returns nil (“not found”).

user=> (some #{1 3} [1 2 3])
1
user=> (some #{1 3} [2 4 6])
nil
user=> (some #{1 3} [3 5 7])
3
user=> (some #{1 3} [4 6 8])
nil

Here we are using a set as a predicate: it returns nil if the argument is not in the set, else it returns the matching element if it is. Now we see that some is returning the first number that is in the set (or nil if none of the numbers being tested are in the set.

Finally, if we look at some?, it is a pure Boolean predicate that returns false if its argument is nil and true otherwise – since we consider nil to be the “absence of a value”:

user=> (some? nil)
false
user=> (some? false)
true
user=> (some? true)
true
user=> (some? [1 2 3])
true

Hope that helps?

Also, as Andy mentioned in another thread, joining the Clojurians Slack and asking these questions in the #beginners channel there will get you immediate feedback and you’ll probably find the interactive nature of Slack more productive for learning than a forum like ClojureVerse.

1 Like

is Slack a pay service? It seems to get an account you have to have an invitation.
Seems I have to contact the workspace administrator for an invitation.
Who’s that?

Go to http://clojurians.net/ & fill in the form with your email for an automatic invite.

Agree with the others that Slack is better for quick answers (though I prefer more async comms myself).

(Slack is freemium for Slack instance administrators. I think Clojurians is on the free tier).

2 Likes

The Clojurians Slack is free and has about 15,000 members (only a portion of which are “active” over time). The downside of the free plan is that only 10,000 messages are accessible so that’s just a “few” days on a high-traffic community like ours. Nearly all messages are mirrored to Clojurians Zulip Chat (completely free, no message limit on history/searches, but not as many people like the UI) and also to a logging site hosted off clojureverse.org – so we can get to the history beyond that 10,000 limit, it’s just not as convenient.

The #beginners channel on Clojurians Slack is smaller than the community as a whole but has a bunch of experienced Clojure developers who have opted in to helping beginners in depth. There are also a lot of specialized channels where you can ask questions about particular libraries or types of problems.

1 Like

Yup, everybody does :wink:

I don’t know how Scheme handles it, but I think this is partially due to the limited number of short meaningful names one can come up with over time for slightly similar yet different behavior functions.

Like you’ll see that there is a: some, some?, every?, any, some-fn, any?, not-any?, some->, some->>, etc.

You can argue you’d had rather swap around some of them and all that, but I think it just so happened that eventually it just became a convoluted real estate space.

I think not all of them came about at the same time, so things just kind of happened.

Anyways, the names of those, and the behavior of contains? I think are the only weird name quirk that come up over and over again. You kind of just have to deal with it.

Like another weird quirk related to these is that the opposite of empty? is seq. And that the opposite of not-any? is not any?, but some.

1 Like