In clojure we are used to shortcuts involving not:

(when-not x ...)         => (when (not x) ...)
(if-not x ...)           => (if (not x) ...)
(not-every? pred coll)   => (not (every? pred coll))
(not-any? pred coll)     => (not (some pred coll))

However, the new function clojure.core/any? breaks this semantic pattern:

​> ​
(doc clojure.core/any?)
-------------------------
clojure.core/any?
([x])
  Returns true given any argument.

​> ​
(doc clojure.core/not-any?)
-------------------------
clojure.core/not-any?
([pred coll])
  Returns false if (pred x) is logical true for any x in coll,
  else true.

​These two functions are not only unrelated to each other, but they don't
even accept the same number or type of arguments.  Moreover, ​there is an
even more surprising property:

> (clojure.core/any? nil)
true

I would have bet money that, at least for nil, the result would not have
been true.
​
Given the significant prior conventions in Clojure​ for functions like
some, every?, *-not, not-*, and also the general handling of nil, it seems
that the new any? function is bound to cause much confusion &
consternation, especially among people learning Clojure.

Given the degenerate definition:

> (source clojure.core/any?)
(defn any?
  [x] true)

would it not be simpler and more instinctive to rename the function
clojure.core/true:

(defn clojure.core/true
  [x] true)

We could then have code with the obvious result:

(true 1)     => true
(true "hi")  => true
(true [])    => true
(true nil)   => true

I believe that such a change would help to keep Clojure in line with users
instincts and assumptions, as well as past Clojure practices.  I have often
felt that one of the most important principles in any sort of software
development is adherence to the Principle of Least Astonishment
<https://en.wikipedia.org/wiki/Principle_of_least_astonishment>.

Alan



On Mon, Jul 11, 2016 at 7:28 AM, Alex Miller <a...@puredanger.com> wrote:

>
> 1.9.0-alpha10 includes the following changes since 1.9.0-alpha9:
>
> - NEW clojure.core/any? - a predicate that matches anything. any? has
> built-in gen support. The :clojure.spec/any spec has been removed.
> Additionally, gen support has been added for some?.
>
>
>
>

-- 
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/d/optout.

Reply via email to