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

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

Re: let, let*, oh, why [was: Elisp - Function returning a list]


From: tomas
Subject: Re: let, let*, oh, why [was: Elisp - Function returning a list]
Date: Wed, 16 Dec 2020 21:34:48 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

On Wed, Dec 16, 2020 at 11:05:36PM +0300, Jean Louis wrote:
> * Stefan Monnier <monnier@iro.umontreal.ca> [2020-12-16 22:05]:
> > >> That doesn't do what you usually want.
> > > Help me to understand why?
> > 
> > https://lists.gnu.org/archive/html/emacs-devel/2020-11/msg00750.html
> 
> Is it possible to show example that it will not work as expected?

Compose a file roughly like this:

  (let ((canary 'lexical))
    (defun test-binding ()
      (insert (format "binding is %S" canary))))

  (let ((canary 'dynamic))
    (test-binding))

Now save it, say as /tmp/foo.el.

Next, from some buffer (say *scratch*), do M-x load-file <ENTER> /tmp/foo.el 
<ENTER>.

This will put in your buffer "binding is dynamic" (since that's the
default).

Now test again

 (1) having inserted (setq lexical-binding t) at the top of the above
     file

 (2)  having inserted -*- lexical-binding: t -*- at the top of the
      above file.

Compare results. Discuss :-)

(Cheatsheet: in case (1), the variable `lexical-binding' has been set
in the buffer from which you called `load-file', which was, if you
chose the same setting as me, *scratch*. In the second case, the
setting of the lexical binding was effective for the source file
itself, i.e. foo.el)

Cheers
 - t

Attachment: signature.asc
Description: Digital signature


reply via email to

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