Fork me on GitHub
#test-check
<
2017-12-01
>
johanatan00:12:31

btw, is it generally considered bad practice to call gen/sample oneself nested within a huge gen/let (or other combinator construct)?

gfredericks00:12:09

Or in a generator at all

gfredericks00:12:35

Same with gen/generate

johanatan00:12:40

hmm, I have through discipline been able to almost always avoid this but sometimes things get so hairy that the way to avoid it is not easy to see.

johanatan00:12:56

is there any standard/general procedure one can apply to help escape that situation?

gfredericks00:12:19

You're passing to sample a generator that's based on other things you generated?

gfredericks00:12:32

I think it can be hard to talk about these things abstractly, but I'm happy to look at whatever code you can share

johanatan00:12:51

@alexmiller would bind work within a gen/let ?

johanatan00:12:18

ah, yep. that seems like it would work.

johanatan00:12:47

is there a function that goes from list of generators to generator of a list?

johanatan00:12:59

[there should be but i'm not seeing it]

johanatan00:12:05

ah, cool. thx

gfredericks00:12:12

Used with apply

johanatan05:12:14

would it be possible to have a generator of an infinite/lazy sequence of arbitrary type?

johanatan05:12:49

[like lazy-random-states but with an arbitrary generator for the values]

johanatan05:12:18

[the reason i'd like this is i have some logic deeply nested inside a gnarly structure of gen/let, gen/bind, gen/fmap et al and realized in the very innermost loop that i need to pull N (dynamically determined) values of a particular type]

johanatan05:12:58

it's probably possible to restructure the code to generate these on the outside but it's a bit difficult given that the amount to be generated is dynamic/ computed/ derived from other values

johanatan05:12:32

so, if i could at the outermost level bind to a lazy sequence, then inside the nests I could pull from that lazy sequence without violating "thou shall not call gen/sample manually"

johanatan05:12:10

pull via a regular take that is

gfredericks12:12:11

I've thought about use cases like that before the trickiest part is thinking about how you shrink that structure

gfredericks12:12:49

you could setup a generator of infinite lazy sequences using a recursive gen/bind, but I think it would never stop shrinking

gfredericks12:12:51

and even with lower-level help from the library, it still needs to have a strategy for that the tension comes from not easily being able to tell how much of the infinite source of data the user actually used

gfredericks12:12:02

there are certainly hacky ways to try to do that, and that might be the best answer, but the "hacky" part has made me hesitant to commit to anything

gfredericks12:12:26

one less hacky trade-off you can make is to relax the "requirement" that there actually be an infinite number of things generated -- e.g., if you generate a large vector of items and then use (gen/fmap cycle ...)

gfredericks12:12:57

then that will naturally shrink to an infinite repetition of one very small piece of data so it only works if you can tolerate repeats

gfredericks12:12:23

I remember making this recommendation for spec when it generates function stubs

johanatan18:12:54

ah, nice thoughts. would definitely be cool if something like this can be added in a not-too-hacky way but for now yea i'll go with a finite but repeating structure

johanatan19:12:59

if i were to attempt a bind to the (gen/fmap cycle ...) structure you mentioned, that would be an infinite loop yea?

gfredericks19:12:53

no I don't think so

gfredericks19:12:13

unless the function that accepts the infinite sequence needs to consume the whole thing before returning a generator

johanatan22:12:11

i made these helpers to realize your idea above:

(defn- repeating-seq
  ([gen] (repeating-seq gen 1000))
  ([gen size] (with-meta (gen/fmap cycle (gen/vector gen size size)) {:size size})))

(defn- take-repeating-seq [n seq]
  (gen/fmap #(take n (drop (%1 1) (%1 0))) (gen/tuple seq (gen/choose 1 ((meta seq) :size)))))

gfredericks23:12:23

So you'd use take-repeating-seq several times on the same generated sequence?

gfredericks23:12:06

You just don't know how many times you need to it until you're doing it?

johanatan23:12:49

mm, well actually i've restructured the code since i did that so haven't had to use it yet. but i see it as a sort of escape hatch if one gets too deep

johanatan23:12:25

[of course i could be totally confused 🙂 ] i always feel about halfway confused when deep in generator code