memoization: (mlambda () ...) allows for inner 'define'.
authorLudovic Courtès <ludo@gnu.org>
Sun, 3 Sep 2017 21:29:11 +0000 (23:29 +0200)
committerLudovic Courtès <ludo@gnu.org>
Sun, 3 Sep 2017 21:36:17 +0000 (23:36 +0200)
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.

guix/memoization.scm

index 5cae283..bf3b73d 100644 (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)))