Memoize redex thunk/e's.

Tests run over twice as fast.
This commit is contained in:
Max New 2013-09-19 01:30:46 -07:00
parent 5c82ab06c3
commit 0f2a640d02

View File

@ -670,11 +670,16 @@
;; thunk/e : Nat or +-Inf, ( -> enum a) -> enum a
(define (thunk/e s thunk)
(enum s
(λ (n)
(decode (thunk) n))
(λ (x)
(encode (thunk) x))))
(let* ([e #f]
[get-e (λ ()
(or e
(and (set! e (thunk))
e)))])
(enum s
(λ (n)
(decode (get-e) n))
(λ (x)
(encode (get-e) x)))))
;; many/e : enum a -> enum (listof a)
;; or : enum a, #:length natural -> enum (listof a)