This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # announcements (1)
- # babashka (2)
- # beginners (17)
- # calva (11)
- # cider (4)
- # clara (3)
- # clj-kondo (19)
- # cljs-dev (60)
- # clojure (27)
- # clojure-europe (1)
- # clojure-nl (2)
- # clojure-spec (1)
- # clojure-uk (11)
- # clojurescript (128)
- # core-logic (7)
- # crux (6)
- # cursive (7)
- # data-science (3)
- # datomic (76)
- # defnpodcast (4)
- # fulcro (5)
- # malli (5)
- # off-topic (7)
- # re-frame (1)
- # reitit (3)
- # shadow-cljs (86)
- # spacemacs (5)
- # test-check (48)
- # tools-deps (9)
- # vim (12)
What would you expect it to do if you tried to cause it to generate a value? Throw an exception?
Can you describe a situation where it would be useful to have a generator that doesn't generate anything? I'm lacking imagination there.
I'm working on regular languages, and I'm willing to construct a generator for words of a given language
If it returns a value, that would be interpreted as a generated valid value, wouldn't it?
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.
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
That would just give you a generator that threw half the time, which is obviously wrong
I don't fully understand why it doesn't make sense, and why e.g
(g/one-of ) is forbidden.
This might be a feature that could be added, but it would have to pervade a lot of the combinators
Like one-of would have to filter out empty generators from its input, for example
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.
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.
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
I guess you could do it that way
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"
That's a pretty deep breaking change, though, so I doubt it would be added as a feature
I ended up working with
nilable generators, and it's not that clumsy so I'll keep it that way
Meaning a generator that generates nil, or a context where you either have a generator or you have nil?