Subject: bug#19828: [PATCH] eval.c: couldn't make closures

From: 尾崎 成一 <[email-masked]>
Date: Tue, 10 Feb 2015 16:25:02 +0900

Hi.

The following code doesn't work because doesn't create any lexical
environment correctly in Emacs 24.4.1.

(defvar my-ticker nil)
;; => my-ticker

(let ((x 0))
  (setq my-ticker (lambda ()
            (setq x (1+ x)))))
;; => (lambda nil
;; =>   (setq x
;; =>     (1+ x)))

(funcall my-ticker)
;; error--> Symbol's value as variable is void: x

After fixing that, it works well.

(defvar my-ticker)
;; => my-ticker

(let ((x 0))
  (setq my-ticker (lambda ()
            (setq x (1+ x)))))
;; => (closure
;; =>  ((x . 0))
;; =>  nil
;; =>  (setq x
;; =>        (1+ x)))

(funcall my-ticker)
;; => 1
(funcall my-ticker)
;; => 2

Regard,
Shigekazu

=== modified file 'src/eval.c'
--- src/eval.c    2014-09-16 04:04:56 +0000
+++ src/eval.c    2015-02-10 06:48:29 +0000
@@ -875,7 +875,7 @@
       val = eval_sub (Fcar (Fcdr (elt)));
     }

-      if (!NILP (lexenv) && SYMBOLP (var)
+      if (SYMBOLP (var)
       && !XSYMBOL (var)->declared_special
       && NILP (Fmemq (var, Vinternal_interpreter_environment)))
     /* Lexically bind VAR by adding it to the interpreter's binding
@@ -953,7 +953,7 @@
       var = SYMBOLP (elt) ? elt : Fcar (elt);
       tem = temps[argnum++];

-      if (!NILP (lexenv) && SYMBOLP (var)
+      if (SYMBOLP (var)
       && !XSYMBOL (var)->declared_special
       && NILP (Fmemq (var, Vinternal_interpreter_environment)))
     /* Lexically bind VAR by adding it to the lexenv alist.  */