all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Pedro Andres Aranda Gutierrez <paaguti@gmail.com>
To: Tim Cross <theophilusx@gmail.com>
Cc: Phil Sainty <psainty@orcon.net.nz>, Eli Zaretskii <eliz@gnu.org>,
	emacs-devel@gnu.org
Subject: Re: PATCH: Explicitly show how let works on global-variables
Date: Wed, 5 Oct 2022 07:28:18 +0200	[thread overview]
Message-ID: <CAO48Bk9NrBYZP_88m8Q8MnR=P-HG+xEavHPbR4jEQCrzoYCN8g@mail.gmail.com> (raw)
In-Reply-To: <86lepvut3l.fsf@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3461 bytes --]

Even more so in the light of lexical binding. I'm trying to introduce
people to Emacs and the easier to understand and use as a source of
inspiration this manual is, the more probable it is that people actually
switch to Emacs. (Or at least this is what I have seen after using it for 7
years as an option in the practical assignments)

/PA

On Wed, 5 Oct 2022 at 00:22, Tim Cross <theophilusx@gmail.com> wrote:

>
> Phil Sainty <psainty@orcon.net.nz> writes:
>
> > On 2022-10-04 21:09, Pedro Andres Aranda Gutierrez wrote:
> >> I understood as local variable a 'value that was stored in the
> >> function's stack' to be used in the scope of the let. That implied
> >> (once again in my understanding) that the global system-time-locale
> >> would not be affected and hence format-time-string would not see the
> >> change in the value within the let.
> >
> > Since the addition of lexical binding to Emacs Lisp in Emacs 24.1,
> > both results are possible depending on whether you are dealing with
> > a dynamic or a lexical variable.
> >
> > I.e. given:
> >
> >  (defun myfunc () foo)
> >  (let ((foo 'bar)) (myfunc))
> >
> > If foo is a dynamic variable then the let form will return 'bar.
> >
> > If foo is a lexical variable, then you'd get this error:
> > "let: Symbol’s value as variable is void: foo".
> >
> > Eli quoted the manual:
> >
> >      Local variables created by a ‘let’ expression retain their value
> >   _only_ within the ‘let’ expression itself (and within expressions
> called
> >   within the ‘let’ expression); the local variables have no effect
> outside
> >   the ‘let’ expression.
> >
> > That "(and within expressions called within the ‘let’ expression)" is
> > pretty ambiguous wrt dynamic vs lexical binding, and a few lines later
> > it comments very briefly on this:
> >
> >   in Emacs Lisp, the default scoping is dynamic, not lexical.
> >   (The non-default lexical binding is not discussed in this manual.)
> >
> > Which keeps the rest of the text accurate, yet in an almost-entirely
> > unexplained manner.
> >
> > I suggest that at this point it has become pretty necessary for lexical
> > binding to be discussed in this manual...
> >
> > * The *scratch* buffer, in which users will perform many if not most of
> >   their experiments, now uses lexical binding by default.
> >
> > * If enabled, auto-insert-mode adds lexical-binding: t to new elisp files
> >   by default.
> >
> > * IIRC most elisp files in Emacs core are now using lexical binding.
> >
> > * The emacs-lisp-mode mode-name treats dynamic binding as a warning.
> >
> > So while it's as true as ever that dynamic binding is the default, the
> > fact that so many things nowadays default to *enabling* lexical binding
> > really blurs this line, to the point where I think it's unreasonable to
> > avoid discussing lexical binding in the introduction to emacs lisp, as
> > the user will almost unavoidably be exposed to it.
> >
> > I think examples would be hugely helpful in explaining the difference
> > between the two types of binding.
> >
>
> +1. I think this has become quite important.
>


-- 
Fragen sind nicht da um beantwortet zu werden,
Fragen sind da um gestellt zu werden
Georg Kreisler

Headaches with a Juju log:
unit-basic-16: 09:17:36 WARNING juju.worker.uniter.operation we should run
a leader-deposed hook here, but we can't yet

[-- Attachment #2: Type: text/html, Size: 4407 bytes --]

  reply	other threads:[~2022-10-05  5:28 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-04  6:46 PATCH: Explicitly show how let works on global-variables Pedro Andres Aranda Gutierrez
2022-10-04  7:52 ` Eli Zaretskii
2022-10-04  8:09   ` Pedro Andres Aranda Gutierrez
2022-10-04 11:36     ` Phil Sainty
2022-10-04 13:43       ` Stefan Monnier
2022-10-04 22:22       ` Tim Cross
2022-10-05  5:28         ` Pedro Andres Aranda Gutierrez [this message]
2022-10-06  9:00           ` Pedro Andres Aranda Gutierrez
2022-10-06 19:34             ` Emanuel Berg
2022-10-04 17:39   ` Richard Stallman
2022-10-04  7:59 ` tomas
2022-10-04 11:56   ` Phil Sainty
2022-10-04 13:48     ` Stefan Monnier
2022-10-05 21:31     ` Richard Stallman
2022-10-04 15:00 ` [External] : " Drew Adams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAO48Bk9NrBYZP_88m8Q8MnR=P-HG+xEavHPbR4jEQCrzoYCN8g@mail.gmail.com' \
    --to=paaguti@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=psainty@orcon.net.nz \
    --cc=theophilusx@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.