Re: any? in clojure 1.9.0 alpha

122 views
Skip to first unread message

Alan Thompson

unread,
Oct 6, 2017, 7:04:16 PM10/6/17
to clo...@googlegroups.com, clojure-dev
Before 1.9.0 is officially released, I would like to propose a revisit to the semantic mismatch introduced by the clojure.core/any? function.

Many, many people are dissatisfied by the choice of clojure.core/any? to be defined as (constantly true), which is completely in conflict with clojure.core/not-any? .    After all, any logical person would automatically assume that:

(= (not-any? args...) (not (any? args...))  

for any set of legal arguments.  This follows the well-established tradition in Clojure of having negated pairs such as if vs if-not,  when vs when-not, every? vs not-every?, etc.

However, I can see that it is convenient to say something like this:

(s/fdef clojure.core/declare
:args (s/cat :names (s/* simple-symbol?))
:ret any?)

It seems a simple solution to the problem would be to just define some keyword specs in place of the globally visible any? function.  The following example shows that we could define :clojure.spec/pass-all and :clojure.spec/pass-none which would could serve as an exact replacement for any? (& its negative).

(:require [clojure.spec.alpha :as s] ...)
(deftest demo
  (s/def ::s/pass-all  (constantly true))
  (s/def ::s/pass-none (constantly false))

  (is      (s/valid? ::s/pass-all 5 ))
  (is      (s/valid? ::s/pass-all "joe" ))
  (is      (s/valid? ::s/pass-all { :blah 42 :blue 66 :hut! 'hut! }))
  (is (not (s/valid? ::s/pass-none 5 ))))

Since 1.9.0 is not out yet, is not too late to avoid a permanent pollution of the language with a gigantic mistake such as any?.  At the very least, the function could be moved to clojure.spec/any? from clojure.core.  If we insist on adding this blatant contradiction to clojure.core, we won't even have the excuse of a committee to blame it on.

Alan Thompson



On Sun, Nov 13, 2016 at 4:15 PM, Nathan Smutz <nsm...@gmail.com> wrote:
Is there a Tricky Names for Nubies page?
We might save some stack-overflow searches.

In the spirit of Honest Trailers: if we named functions for what they do:
or    -> first-truthy
some  -> first-satisfying
some? -> not-nil?
any?  -> return-true

Are there others?

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+unsubscribe@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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alex Miller

unread,
Oct 6, 2017, 7:55:14 PM10/6/17
to cloju...@googlegroups.com, clo...@googlegroups.com
This ship has sailed.
You received this message because you are subscribed to the Google Groups "Clojure Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure-dev...@googlegroups.com.
To post to this group, send email to cloju...@googlegroups.com.
Visit this group at https://groups.google.com/group/clojure-dev.
Reply all
Reply to author
Forward
0 new messages