test-check

2019-11-03T09:17:21.000700Z

does the empty generator exist ?

2019-11-03T16:47:23.001400Z

meaning, fails to generate anything?

2019-11-03T16:47:44.001700Z

yes

2019-11-03T16:48:03.002500Z

What would you expect it to do if you tried to cause it to generate a value? Throw an exception?

2019-11-03T16:48:10.002800Z

Can make it with such-that, if so

2019-11-03T16:49:07.003600Z

Can you describe a situation where it would be useful to have a generator that doesn't generate anything? I'm lacking imagination there.

2019-11-03T16:51:43.004900Z

I'm working on regular languages, and I'm willing to construct a generator for words of a given language

2019-11-03T16:52:26.005600Z

so, does it makes sense to have a generator for words of the empty language ?

2019-11-03T16:52:46.005900Z

Sure

2019-11-03T16:52:57.006200Z

Would it just throw an exception when you tried to generate such a word?

2019-11-03T16:53:19.006600Z

no, because it's not error

2019-11-03T16:53:21.006800Z

I'd hope so

2019-11-03T16:53:36.007600Z

If it returns a value, that would be interpreted as a generated valid value, wouldn't it?

2019-11-03T16:53:37.007700Z

What would it generate then?

2019-11-03T16:54:23.008100Z

it would generate nothing

2019-11-03T16:54:43.008400Z

What would a call to samples return? (edit: I meant a call to gen/sample)

2019-11-03T16:54:57.008600Z

an empty list

2019-11-03T16:55:12.009200Z

There's no such thing as generating nothing

2019-11-03T16:55:57.010200Z

Similar to there's no such thing as a function that returns nothing

2019-11-03T16:57:21.011200Z

e.g. a generator that returns nil is thereby indicating: nil is a value that satisfies the desired predicate. Not that there is no valid value satisfying the predicate.

2019-11-03T17:01:42.015200Z

I guess a downside of using a throwing generator for the empty language is that test.check wouldn't let you do things like create a disjunction using gen/one-of like you'd want to

2019-11-03T17:02:06.016100Z

That would just give you a generator that threw half the time, which is obviously wrong

2019-11-03T17:02:14.016200Z

I don't fully understand why it doesn't make sense, and why e.g (g/one-of []) is forbidden.

2019-11-03T17:02:47.017100Z

this is really a noob question, I'm not really familiar with this topic

2019-11-03T17:02:59.017500Z

This might be a feature that could be added, but it would have to pervade a lot of the combinators

2019-11-03T17:03:46.018800Z

Like one-of would have to filter out empty generators from its input, for example

2019-11-03T17:04:03.019600Z

fmap and bind would have to short circuit

2019-11-03T17:04:09.019900Z

And on and on

2019-11-03T17:04:54.021200Z

Well, if you used such-that with an arbitrary function predicate that always returned false, test.check would have no general way to identify all possible generate-nothing generators. It could only recognize ones that you made obvious were generating-nothing generators.

2019-11-03T17:05:07.021500Z

Yes

2019-11-03T17:05:17.021900Z

Which is why the pervasive support is important

2019-11-03T17:05:30.022400Z

To track emptiness

2019-11-03T17:06:08.024200Z

So one-of would have to try invoking empty generators, and have a way of getting back "I didn't generate anything", wouldn't it? i.e. in order to enable arbitrary empty gens.

2019-11-03T17:06:11.024400Z

And this would still be a generator that throws when you try to generate, so if that can't be useful to you, then even this idea wouldn't help

2019-11-03T17:07:05.025800Z

Not sure how that would affect the usability of such-that

2019-11-03T17:07:37.027200Z

Not recommending that approach, necessarily, but it seems like one approach, the other being to say something like "empty gens using such-that with arbitrary Clojure functions as predicates may throw exceptions, or some other behavior you might not like, if you try to use them"

2019-11-03T17:07:39.027400Z

That's a pretty deep breaking change, though, so I doubt it would be added as a feature

2019-11-03T17:12:47.028700Z

is (g/such-that (constantly false) generator) a terrible idea ?

2019-11-03T17:13:07.029300Z

No, but it throws, and you said you didn't want that

2019-11-03T17:13:29.030Z

Also it doesn't compose like I suspect you'd want for regular languages

2019-11-03T17:14:11.030900Z

But if you use it without composing, it'd work fine

2019-11-03T17:14:23.031200Z

that matches my intuition

2019-11-03T17:15:20.031900Z

I ended up working with nilable generators, and it's not that clumsy so I'll keep it that way

2019-11-03T17:16:16.033100Z

Meaning a generator that generates nil, or a context where you either have a generator or you have nil?

2019-11-03T17:16:31.033300Z

the latter

2019-11-03T17:16:40.033600Z

Sounds fine

2019-11-03T17:17:15.033800Z

OK thank you for clarification

👍 1