Re: [racket-users] how to make a cartesian supergenerator?

2018-10-21 Thread Matthew Butterick
> On Oct 21, 2018, at 3:49 PM, Jay McCarthy wrote: > > I think the best strategy would be to convert the generator to a > sequence and then the sequence to a stream, then write a stream > cartesian product. The stream will cache the results of the generator. Nice. #lang racket (require ra

Re: [racket-users] Re: how to make a cartesian supergenerator?

2018-10-21 Thread Robby Findler
If I am understanding this right, data/enumerate's list/e combinator doing a similar job. It might also be helpful. Robby On Sun, Oct 21, 2018 at 5:50 PM Jay McCarthy wrote: > I think the best strategy would be to convert the generator to a > sequence and then the sequence to a stream, then wri

Re: [racket-users] Re: how to make a cartesian supergenerator?

2018-10-21 Thread Jay McCarthy
I think the best strategy would be to convert the generator to a sequence and then the sequence to a stream, then write a stream cartesian product. The stream will cache the results of the generator. On Sun, Oct 21, 2018 at 4:58 PM Matthew Butterick wrote: > > I suppose just putting in a hash isn'

[racket-users] Re: how to make a cartesian supergenerator?

2018-10-21 Thread Matthew Butterick
I suppose just putting in a hash isn't too bad. #lang racket (require racket/generator rackunit) (define/contract (make-cartesian-generator gens) ((listof generator?) . -> . generator?) (generator () (define solcache (make-hasheqv)) (let loop ([gens gens][genidx 0][

[racket-users] how to make a cartesian supergenerator?

2018-10-21 Thread Matthew Butterick
The sample below tries to make a "cartesian supergenerator" that takes several smaller generators and combines them into a larger generator that yields cartesian combinations of the results. This works on the first pass (when the result of g1=1). But when the result of g1=2, the g2 generator is