[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [elpa] master b5f4061: Drop forced lambda's from stream (Bug#30626)
From: |
Stefan Monnier |
Subject: |
Re: [elpa] master b5f4061: Drop forced lambda's from stream (Bug#30626) |
Date: |
Tue, 04 Jun 2019 09:27:09 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
> Let the stream id distinguish between forced and unforced stream
> values. When the value is forced, replace the lambda with its result.
> This lets the lambda and anything it references be garbage collected.
Doesn't the same "memory leak" affect thunks?
How 'bout the patch below
Stefan
diff --git a/lisp/emacs-lisp/thunk.el b/lisp/emacs-lisp/thunk.el
index e1370c4591..8d28570dc2 100644
--- a/lisp/emacs-lisp/thunk.el
+++ b/lisp/emacs-lisp/thunk.el
@@ -54,16 +54,15 @@ thunk-delay
"Delay the evaluation of BODY."
(declare (debug t))
(cl-assert lexical-binding)
- (let ((forced (make-symbol "forced"))
- (val (make-symbol "val")))
- `(let (,forced ,val)
- (lambda (&optional check)
- (if check
- ,forced
- (unless ,forced
- (setf ,val (progn ,@body))
- (setf ,forced t))
- ,val)))))
+ `(let (forced
+ (val (lambda () ,@body)))
+ (lambda (&optional check)
+ (if check
+ forced
+ (unless forced
+ (setf val (funcall val))
+ (setf forced t))
+ val))))
(defun thunk-force (delayed)
"Force the evaluation of DELAYED.
- Re: [elpa] master b5f4061: Drop forced lambda's from stream (Bug#30626),
Stefan Monnier <=