From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tim Cross Newsgroups: gmane.emacs.devel Subject: Re: PATCH: Explicitly show how let works on global-variables Date: Wed, 05 Oct 2022 09:22:02 +1100 Message-ID: <86lepvut3l.fsf@gmail.com> References: <83czb8vxdo.fsf@gnu.org> <08f6be68d07b1c3ee3c65f8fb6842eb3@webmail.orcon.net.nz> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30184"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.9.0; emacs 29.0.50 Cc: Pedro Andres Aranda Gutierrez , Eli Zaretskii , emacs-devel@gnu.org To: Phil Sainty Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Oct 05 00:26:41 2022 Return-path: Envelope-to: ged-emacs-devel@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 ) id 1ofqN7-0007hN-5F for ged-emacs-devel@m.gmane-mx.org; Wed, 05 Oct 2022 00:26:41 +0200 Original-Received: from localhost ([::1]:52742 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofqN5-0004wE-2J for ged-emacs-devel@m.gmane-mx.org; Tue, 04 Oct 2022 18:26:39 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48964) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofqJK-0008W9-Qa for emacs-devel@gnu.org; Tue, 04 Oct 2022 18:22:46 -0400 Original-Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]:39705) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ofqJI-0001iW-US; Tue, 04 Oct 2022 18:22:46 -0400 Original-Received: by mail-pf1-x434.google.com with SMTP id d10so14304411pfh.6; Tue, 04 Oct 2022 15:22:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:in-reply-to:date :subject:cc:to:from:user-agent:references:from:to:cc:subject:date; bh=vIIla8LRFw4ebf8ksP6EPuhZsfHxdDzGU7MVW3orLjs=; b=LBcK/LknFPIeOZLdIWA2XYwhdZ4PZcTyt5wg76A4+luCwOR451cN5Ukm5q7Sml90zI is2vdwpS2eDoc/7aahTg8z+PWR9y13B3vdEzasBvRaGivMa5UVhygU1YXXUs78jknDZt 5x+8FikCCzGb7y6IzvxK++TdhktbBHd2/digNl85sF+kRYneG/onfkV70FIgGmrnKid/ f1HNtTo7EhG7JFqFArayjtjN/hJdhZdpaDc0h2m40v0jtRZULiGjDXM4ZdnndrkApSBs svvEwxsWierliuj8lmJ7h9erhmbKOYH+h49OReJS746PQPpzNobI6RMxc/6yGvLxeMBE +kjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:in-reply-to:date :subject:cc:to:from:user-agent:references:x-gm-message-state:from:to :cc:subject:date; bh=vIIla8LRFw4ebf8ksP6EPuhZsfHxdDzGU7MVW3orLjs=; b=xkTFg5griR6sxClqU+xYptjr3Tu520It2Mo6cA2rHriQVyvbF9ACO97+1To8CTPknp dqqym3YWqx6shv8+dc/cdUx/s+5iARDSF150VVUf/vDK+yS49l6J3zlKhtZ9IMRV3Ulp sz0vz6pNb4wVvnHIcp2dc3umssRPMjVXH3EWcCPlMHS4TxYBhT/p7lxR2WkRIZ7LNLRZ kpp+EmZ70MkncJTiqkvHDnggRQMoYykomwoP/fREXZylD6gvTvq6J7R/WQsbrKE/yNdC cDGbgeDu0lhV9pgJvmyjAXBT1PJcNhrZNR5+L8KC3Q+6/bs9mCw6uS6dueI905bScRSR as/g== X-Gm-Message-State: ACrzQf3HkWcxFsy84FKS4zh1JeERG6xrGFpDoqfr6Fcr7LBbo+UcmXje x/5ITyAaf5TvXwG/OYP8I+Sr3x2c3Cc= X-Google-Smtp-Source: AMsMyM7omdkDQmefmLkertxgsU/h1z3wBkuhShDV+DtfbTJxOZHs/I+VkndIrIB+6laAXcL1ySsUGg== X-Received: by 2002:a65:4303:0:b0:439:f026:ccee with SMTP id j3-20020a654303000000b00439f026cceemr25094167pgq.322.1664922162786; Tue, 04 Oct 2022 15:22:42 -0700 (PDT) Original-Received: from dingbat (124-169-22-230.dyn.iinet.net.au. [124.169.22.230]) by smtp.gmail.com with ESMTPSA id ch17-20020a17090af41100b001f2fa09786asm50840pjb.19.2022.10.04.15.22.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 15:22:42 -0700 (PDT) In-reply-to: <08f6be68d07b1c3ee3c65f8fb6842eb3@webmail.orcon.net.nz> Received-SPF: pass client-ip=2607:f8b0:4864:20::434; envelope-from=theophilusx@gmail.com; helo=mail-pf1-x434.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:296933 Archived-At: Phil Sainty 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=E2=80=99s value as variable is void: foo". > > Eli quoted the manual: > > Local variables created by a =E2=80=98let=E2=80=99 expression retain= their value > _only_ within the =E2=80=98let=E2=80=99 expression itself (and within e= xpressions called > within the =E2=80=98let=E2=80=99 expression); the local variables have = no effect outside > the =E2=80=98let=E2=80=99 expression. > > That "(and within expressions called within the =E2=80=98let=E2=80=99 exp= ression)" 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.