nothing? predicate

302 views
Skip to first unread message

Ambrose Bonnaire-Sergeant

unread,
Jul 10, 2017, 2:11:41 PM7/10/17
to cloju...@googlegroups.com
Hi,

Is (defn nothing? [_] false) being missing from clojure.core an
oversight or intentional?

Thanks,
Ambrose

Alex Miller

unread,
Jul 10, 2017, 2:46:49 PM7/10/17
to cloju...@googlegroups.com
Asking why a thing doesn't exist is not a good way to start a design discussion. Please describe a problem and we can look at alternative solutions.

Is (defn forty-two? [x] (= 42 x)) being missing from clojure.core an oversight or intentional?

There are an infinite number of things not in clojure.core. Slightly less than 100% of those are missing neither because they were oversights nor intentional omissions but because they don't solve a problem.



--
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+unsubscribe@googlegroups.com.
To post to this group, send email to cloju...@googlegroups.com.
Visit this group at https://groups.google.com/group/clojure-dev.
For more options, visit https://groups.google.com/d/optout.

Ambrose Bonnaire-Sergeant

unread,
Jul 10, 2017, 3:30:40 PM7/10/17
to cloju...@googlegroups.com
My mistake. Thanks!

Ambrose Bonnaire-Sergeant

unread,
Jul 10, 2017, 5:49:45 PM7/10/17
to cloju...@googlegroups.com
So, a second stab at the original post that I deleted a dozen times from anxiety...for posterity.

It's basically a summary of a journey starting with wondering what (s/coll-of (s/or))
would do, since my spec tool generated it for empty collections.

   user=> (s/exercise (s/coll-of (s/or)))

   ExceptionInfo Unable to construct gen at: [] for: (or)

Ok, let's constrict :count to 0.

   user=> (s/exercise (s/coll-of (s/or) :count 0))

   ExceptionInfo Unable to construct gen at: [] for: (or)

Huh, didn't work. I'm assuming clojure.spec generates values until it finds an empty one?
Oh, this works though:

   user=> (s/exercise empty?)
   ([#{} #{}] [#{} #{}] [() ()] ...)

I was imagining (s/coll-of nothing?) could generate useful values if it existed.

Sorry about the mess.

Thanks,
Ambrose

Alex Miller

unread,
Jul 10, 2017, 6:23:23 PM7/10/17
to Clojure Dev, abonnair...@gmail.com

On Monday, July 10, 2017 at 4:49:45 PM UTC-5, Ambrose Bonnaire-Sergeant wrote:
So, a second stab at the original post that I deleted a dozen times from anxiety...for posterity.

Thanks, this is a lot more useful starting point!
 
It's basically a summary of a journey starting with wondering what (s/coll-of (s/or))
would do, since my spec tool generated it for empty collections.

   user=> (s/exercise (s/coll-of (s/or)))

   ExceptionInfo Unable to construct gen at: [] for: (or)

The exception here is coming out of generating from s/or:

user=> (gen/sample (s/gen (s/or)))
ExceptionInfo Unable to construct gen at: [] for: clojure.spec.alpha$or_spec_impl$reify__810@6aa61224

The generator built for s/or is a choice between the generators for the preds of the or. If there are no preds, then there are no generators, and nothing can be generated. So that leads to the question of what s/or should generate if there are no preds. 

Seems like you're suggesting that s/or could implicitly include a nothing? predicate which would come into play in this case (and s/and would implicitly include any?). A nothing? (or none? to be like any?) predicate would by definition be unable to produce a value, but it would allow you to actually create the generator. And that may be enough to allow the surrounding s/coll-of to produce empty colls.

 
Ok, let's constrict :count to 0.

   user=> (s/exercise (s/coll-of (s/or) :count 0))

   ExceptionInfo Unable to construct gen at: [] for: (or)

Huh, didn't work. I'm assuming clojure.spec generates values until it finds an empty one?

The problem is in actually constructing the generator in the first place, as it requires at least one generator to make a choice between. I don't believe it's even getting to the point where it tries to construct values, but perhaps it could with a none? generator.
 
Oh, this works though:

   user=> (s/exercise empty?)
   ([#{} #{}] [#{} #{}] [() ()] ...)

I was imagining (s/coll-of nothing?) could generate useful values if it existed.

Possibly. There may be ways to get here without an explicit nothing? predicate though.

If you want to file something, go for it, although this is pretty far down the list in priority.
Reply all
Reply to author
Forward
0 new messages