me
/
guix
Archived
1
0
Fork 0

memoization: (mlambda () ...) allows for inner 'define'.

Previously (mlambda () (define foo 2) bar) would trigger a syntax error.

* guix/memoization.scm (%mlambda): In the zero-argument case, move
BODY... to a lambda to allow for inner 'define' and such.
master
Ludovic Courtès 2017-09-03 23:29:11 +02:00
parent 4363767394
commit e3c83a7cd3
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
1 changed files with 3 additions and 2 deletions

View File

@ -76,10 +76,11 @@ the result is returned via (apply values results)."
exactly one value."
((_ cached () body ...)
;; The zero-argument case is equivalent to a promise.
(let ((result #f) (cached? #f))
(let ((result #f) (cached? #f)
(compute (lambda () body ...)))
(lambda ()
(unless cached?
(set! result (begin body ...))
(set! result (compute))
(set! cached? #t))
result)))