From mboxrd@z Thu Jan  1 00:00:00 1970
Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail
From: Eli Zaretskii <eliz@gnu.org>
Newsgroups: gmane.emacs.bugs
Subject: bug#66756: 30.0.50;
 [PATCH] Improve discussion of 'let' in Elisp Introduction manual
Date: Sat, 04 Nov 2023 10:27:51 +0200
Message-ID: <83fs1l6hyw.fsf@gnu.org>
References: <a9812c1d-71e4-5f3f-83a4-a2923e649f3a@gmail.com>
 <a5120e2f-b008-1b74-1ad9-3fe7d861b13c@gmail.com>
Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214";
	logging-data="21220"; mail-complaints-to="usenet@ciao.gmane.io"
Cc: Jim Porter <jporterbugs@gmail.com>, 66756@debbugs.gnu.org
To: Richard Stallman <rms@gnu.org>
Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Nov 04 09:28:48 2023
Return-path: <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org>
Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org
Original-Received: from lists.gnu.org ([209.51.188.17])
	by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
	(Exim 4.92)
	(envelope-from <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org>)
	id 1qzC1O-0005IM-7t
	for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 04 Nov 2023 09:28:46 +0100
Original-Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <bug-gnu-emacs-bounces@gnu.org>)
	id 1qzC15-0005gu-Ed; Sat, 04 Nov 2023 04:28:27 -0400
Original-Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>)
 id 1qzC14-0005gm-Nj
 for bug-gnu-emacs@gnu.org; Sat, 04 Nov 2023 04:28:26 -0400
Original-Received: from debbugs.gnu.org ([2001:470:142:5::43])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>)
 id 1qzC14-0004ki-FN
 for bug-gnu-emacs@gnu.org; Sat, 04 Nov 2023 04:28:26 -0400
Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2)
 (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1qzC1d-0007do-LE
 for bug-gnu-emacs@gnu.org; Sat, 04 Nov 2023 04:29:01 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Eli Zaretskii <eliz@gnu.org>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@gnu.org
Resent-Date: Sat, 04 Nov 2023 08:29:01 +0000
Resent-Message-ID: <handler.66756.B66756.169908652229341@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 66756
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
Original-Received: via spool by 66756-submit@debbugs.gnu.org id=B66756.169908652229341
 (code B ref 66756); Sat, 04 Nov 2023 08:29:01 +0000
Original-Received: (at 66756) by debbugs.gnu.org; 4 Nov 2023 08:28:42 +0000
Original-Received: from localhost ([127.0.0.1]:60489 helo=debbugs.gnu.org)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
 id 1qzC1J-0007dA-O1
 for submit@debbugs.gnu.org; Sat, 04 Nov 2023 04:28:42 -0400
Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58772)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@gnu.org>) id 1qzC1I-0007cv-3I
 for 66756@debbugs.gnu.org; Sat, 04 Nov 2023 04:28:40 -0400
Original-Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@gnu.org>)
 id 1qzC0c-0004hs-NO; Sat, 04 Nov 2023 04:27:58 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=PQIuBbTL7taVCJPMSHY6sljJE562Q9HEcQ4vn2MU6OA=; b=RbxIMFdg3b0B
 qNp8DqnUQpeFfykiOy5CyNVDEQ8ty63JvnEbDximA0KldyxJzmTVe8rC1tk0aRlxqh3JpgfSutGFL
 ZxCLEh2Xdyi5MjMep/JUUFpqTo8llvQyAY8WloXf4VfapUQkcITWVdJX4pGemuHnNipcyTyYcyEWl
 SSkP9qXbe53IaC93TD3LqNB13t8TfqrtklnvqMUTcs3XwOGeIAHhTQNyKiYFAvXD8+ZPU7VvVOFWk
 76Exg9LkmfgGA8d/aMzdP5LsXh31/cDwbFf4PR8f+73Epdse2suUvvPo/F+MVU44DWNF2qliL1oFG
 qVBQtdavPgn2RTfH/6d7Mg==;
In-Reply-To: <a5120e2f-b008-1b74-1ad9-3fe7d861b13c@gmail.com> (message from
 Jim Porter on Thu, 26 Oct 2023 11:30:46 -0700)
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
X-BeenThere: bug-gnu-emacs@gnu.org
List-Id: "Bug reports for GNU Emacs,
 the Swiss army knife of text editors" <bug-gnu-emacs.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-gnu-emacs>,
 <mailto:bug-gnu-emacs-request@gnu.org?subject=unsubscribe>
List-Archive: <https://lists.gnu.org/archive/html/bug-gnu-emacs>
List-Post: <mailto:bug-gnu-emacs@gnu.org>
List-Help: <mailto:bug-gnu-emacs-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-gnu-emacs>,
 <mailto:bug-gnu-emacs-request@gnu.org?subject=subscribe>
Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org
Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org
Xref: news.gmane.io gmane.emacs.bugs:273753
Archived-At: <http://permalink.gmane.org/gmane.emacs.bugs/273753>

> Date: Thu, 26 Oct 2023 11:30:46 -0700
> From: Jim Porter <jporterbugs@gmail.com>
> 
> On 10/26/2023 12:09 AM, Eli Zaretskii wrote:
>  > Thanks.
>  >
>  > The challenge in updating the Lisp Introduction manual is to try to
>  > keep its informal and reader-friendly style as much as possible.  It
>  > is not just another ELisp Reference manual!  So please try to keep
>  > that in mind when you write the text, and in particular try not to
>  > modify the existing text that is still accurate -- it was written by a
>  > master, and each word there counts, even if it looks at first sight as
>  > not important.
> 
> Ok, here's a second attempt. I've tried to avoid changing anything that 
> I don't think is truly necessary. I did alter a bit of the original 
> wording to emphasize that under lexical binding, 'let' isn't about time, 
> but about place. For example, that's why I changed this:
> 
> > This is like understanding that whenever your host refers to ``the house'', he means his house, not yours.
> 
> to this:
> 
> > This is like understanding that in your host's home, whenever he refers to ``the house'', he means his house, not yours.
> 
> My previous concern about the "lexical binding" digression still applies 
> though. However, I'm not sure how to get around that at present; if we 
> want to talk about lexical binding in the manual, we need to get users 
> to enable it, so I think it's unavoidable that we at least mention it. I 
> tried to introduce the jargon as gently as I could (by first introducing 
> the term "binding" on its own before mentioning "lexical/dynamic 
> binding"), but it's still a bit intimidating. On the positive side, when 
> lexical binding is the default, we could remove that entire digression.
> 
> There's also an argument that the example I added is in the wrong spot, 
> since we haven't actually introduced the 'let' syntax yet. However, I 
> personally find the example to be pretty useful since it shows off one 
> of the key differences between lexical and dynamic binding, and helps 
> show one of the boundaries of the 'let' form's scope. I myself tend to 
> learn best by seeing examples of that sort. Fixing the order so we 
> introduce the syntax first would require more extensive changes to this 
> section...

Richard, could you please review these changes?

> From 12847e0d59b2de3791efa090addc0169e713e6d1 Mon Sep 17 00:00:00 2001
> From: Jim Porter <jporterbugs@gmail.com>
> Date: Wed, 25 Oct 2023 20:43:57 -0700
> Subject: [PATCH] Introduce 'let' using lexical binding in the Lisp
>  Introduction
> 
> * doc/lispintro/emacs-lisp-intro.texi (Prevent confusion): Rework the
> explanation to discuss how things work under lexical binding
> (including how to enable it).
> ---
>  doc/lispintro/emacs-lisp-intro.texi | 67 ++++++++++++++++++++++-------
>  1 file changed, 51 insertions(+), 16 deletions(-)
> 
> diff --git a/doc/lispintro/emacs-lisp-intro.texi b/doc/lispintro/emacs-lisp-intro.texi
> index fce7583fe91..e805833f979 100644
> --- a/doc/lispintro/emacs-lisp-intro.texi
> +++ b/doc/lispintro/emacs-lisp-intro.texi
> @@ -3602,24 +3602,59 @@ Prevent confusion
>  @cindex @samp{variable, local}, defined
>  The @code{let} special form prevents confusion.  @code{let} creates a
>  name for a @dfn{local variable} that overshadows any use of the same
> -name outside the @code{let} expression.  This is like understanding
> -that whenever your host refers to ``the house'', he means his house, not
> -yours.  (Symbols used in argument lists work the same way.
> +name outside the @code{let} expression (in computer science jargon, we
> +call this ``binding'' the variable).  This is like understanding that
> +in your host's home, whenever he refers to ``the house'', he means his
> +house, not yours.  (Symbols used in argument lists work the same way.
>  @xref{defun, , The @code{defun} Macro}.)
>  
> -Local variables created by a @code{let} expression retain their value
> -@emph{only} within the @code{let} expression itself (and within
> -expressions called within the @code{let} expression); the local
> -variables have no effect outside the @code{let} expression.
> -
> -Another way to think about @code{let} is that it is like a @code{setq}
> -that is temporary and local.  The values set by @code{let} are
> -automatically undone when the @code{let} is finished.  The setting
> -only affects expressions that are inside the bounds of the @code{let}
> -expression.  In computer science jargon, we would say the binding of
> -a symbol is visible only in functions called in the @code{let} form;
> -in Emacs Lisp, the default scoping is dynamic, not lexical.  (The
> -non-default lexical binding is not discussed in this manual.)
> +@cindex lexical binding
> +@cindex binding, lexical
> +@cindex dynamic binding
> +@cindex binding, dynamic
> +Before we begin discussing @code{let} in detail, we must first mention
> +an important note.  For historical reasons, Emacs Lisp uses a form of
> +variable binding called ``dynamic binding''.  However, this manual
> +will discuss the preferred form of binding, called ``lexical binding''
> +(if you have programmed in other languages before, you're likely
> +already familiar with how lexical binding behaves).  In order to use
> +lexical binding, you should add something like this to the first line
> +of your Emacs Lisp file:
> +
> +@example
> +;;; -*- lexical-binding: t -*-
> +@end example
> +
> +For more information about this, @pxref{Selecting Lisp Dialect, , ,
> +elisp, The Emacs Lisp Reference Manual}.
> +
> +With that out of the way, we can get back to discussing @code{let}.
> +Another way to think about @code{let} is that it defines a place in
> +your code where the variables you named have their own local meaning.
> +Outside of the @code{let} body, they have another meaning (or they may
> +not be defined at all).
> +
> +This means that inside the @code{let} body, calling @code{setq}
> +for a variable named by the @code{let} expression will set the value
> +of the @emph{local} variable of that name.  This also means that
> +outside of the @code{let} body, calling @code{setq} for a variable
> +named by the @code{let} expression will @emph{not} affect that local
> +variable.
> +
> +For example, if you call a function inside of a @code{let}
> +body, that function's body would be unable to ``see'' (or modify) the
> +value of a local variable from the @code{let} expression:
> +
> +@example
> +(setq x 1)
> +
> +(defun getx ()
> +  x)
> +
> +(let ((x 2))
> +  (get-x))
> +     @result{} 1
> +@end example
>  
>  @code{let} can create more than one variable at once.  Also,
>  @code{let} gives each variable it creates an initial value, either a
> -- 
> 2.25.1
>