From 5840ef1cc89ad7eb2e18f1d06a8e0aaa5e1f6848 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sun, 21 Oct 2018 17:16:44 -0700 Subject: [PATCH] dreamy streamy --- csp/hacs.rkt | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/csp/hacs.rkt b/csp/hacs.rkt index 26f92106..23a2cc84 100644 --- a/csp/hacs.rkt +++ b/csp/hacs.rkt @@ -491,19 +491,14 @@ (define/contract (make-cartesian-generator solgens) ((listof generator?) . -> . generator?) (generator () - (define solcache (make-hasheqv)) - (let loop ([solgens solgens][idx 0][sols empty]) - (match solgens - [(? empty?) (yield (combine-csps (reverse sols)))] - [(cons solgen rest) - (cond - [(eq? (generator-state solgen) 'done) - (for ([sol (in-list (reverse (hash-ref solcache idx)))]) - (loop rest (add1 idx) (cons sol sols)))] - [else - (for ([sol (in-producer solgen (void))]) - (hash-update! solcache idx (λ (vals) (cons sol vals)) null) - (loop rest (add1 idx) (cons sol sols)))])])))) + (define solstreams (for/list ([solgen (in-list solgens)]) + (for/stream ([sol (in-producer solgen (void))]) + sol))) + (let loop ([solstreams solstreams][sols empty]) + (if (null? solstreams) + (yield (combine-csps (reverse sols))) + (for ([sol (in-stream (car solstreams))]) + (loop (cdr solstreams) (cons sol sols))))))) (define/contract (extract-subcsp csp names) ($csp? (listof name?) . -> . $csp?)