help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: run-with-timer does not display message


From: Sebastian Wiesner
Subject: Re: run-with-timer does not display message
Date: Sun, 20 Jul 2014 14:15:19 +0200
User-agent: KMail/4.13.3 (Linux/3.16.0-0.rc5.git1.1.fc22.x86_64; KDE/4.13.3; x86_64; ; )

Am Samstag, 19. Juli 2014, 19:43:16 schrieb Emanuel Berg:

> 2. Interestingly, what I can see, my method, with
>    backticks and commas, isn't that "lexical" - because
>    then, there, the actual values are inserted?

Note quite.  The backquote is “static” in that it captures the *value* of the 
variable at the time the backquote is evaluated.  “Lexical” binding captures 
the *variable itself*.

This makes a difference if the variable is changed after capturing.  
Considering the following example:

ELISP> (let ((i 10))
         (setq f-lexical (lambda () i))
         (setq f-backquote `(lambda () ,i))
         (setq i 20))
20 (#o24, #x14, ?\C-t)
ELISP> (funcall f-lexical)
20 (#o24, #x14, ?\C-t)
ELISP> (funcall f-backquote)
10 (#o12, #xa, ?\C-j)

As you can see, changing "i" *after* creating the functions only affects the 
closure created by lexical binding.  The function created by the backquote is 
left untouched.

This specific behaviour is what makes lexical binding special:  Capturing 
*lexical variables* in closures, as opposed to capturing values (by 
backquotes) or just using dynamic variables.  You cannot easily and 
efficiently emulated this behaviour with macros and backquotes.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]