unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#19828: [PATCH] eval.c: couldn't make closures
@ 2015-02-10  7:25 尾崎 成一
  2015-02-10 10:18 ` Shigekazu Ozaki
  2015-02-10 11:17 ` Nicolas Richard
  0 siblings, 2 replies; 4+ messages in thread
From: 尾崎 成一 @ 2015-02-10  7:25 UTC (permalink / raw)
  To: 19828

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.  */





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#19828: [PATCH] eval.c: couldn't make closures
  2015-02-10  7:25 bug#19828: [PATCH] eval.c: couldn't make closures 尾崎 成一
@ 2015-02-10 10:18 ` Shigekazu Ozaki
  2015-02-10 11:17 ` Nicolas Richard
  1 sibling, 0 replies; 4+ messages in thread
From: Shigekazu Ozaki @ 2015-02-10 10:18 UTC (permalink / raw)
  To: 19828

Sorry everyone, if you attach this patch, Info-menu command won't work.





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#19828: [PATCH] eval.c: couldn't make closures
  2015-02-10  7:25 bug#19828: [PATCH] eval.c: couldn't make closures 尾崎 成一
  2015-02-10 10:18 ` Shigekazu Ozaki
@ 2015-02-10 11:17 ` Nicolas Richard
  2015-02-10 12:06   ` Shigekazu Ozaki
  1 sibling, 1 reply; 4+ messages in thread
From: Nicolas Richard @ 2015-02-10 11:17 UTC (permalink / raw)
  To: 尾崎 成一; +Cc: 19828

Hello,

尾崎 成一 <mitararu@gmail.com> writes:
> The following code doesn't work because doesn't create any lexical
> environment correctly in Emacs 24.4.1.

I think this is not a bug. In order for emacs to create closures, you
need to enable lexical-binding (usually done via a file local variable
at the top of the file, e.g. using add-file-local-variable-prop-line).

See (info "(elisp) Closures").

HTH,

-- 
Nicolas Richard





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#19828: [PATCH] eval.c: couldn't make closures
  2015-02-10 11:17 ` Nicolas Richard
@ 2015-02-10 12:06   ` Shigekazu Ozaki
  0 siblings, 0 replies; 4+ messages in thread
From: Shigekazu Ozaki @ 2015-02-10 12:06 UTC (permalink / raw)
  To: Nicolas Richard; +Cc: 19828

>> The following code doesn't work because doesn't create any lexical
>> environment correctly in Emacs 24.4.1.
>
> I think this is not a bug. In order for emacs to create closures, you
> need to enable lexical-binding (usually done via a file local variable
> at the top of the file, e.g. using add-file-local-variable-prop-
> line).
>
> See (info "(elisp) Closures").

I see. I've misunderstood about the lexical bindings. Thank you. It's
very kind of you.





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-02-10 12:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-10  7:25 bug#19828: [PATCH] eval.c: couldn't make closures 尾崎 成一
2015-02-10 10:18 ` Shigekazu Ozaki
2015-02-10 11:17 ` Nicolas Richard
2015-02-10 12:06   ` Shigekazu Ozaki

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).