From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: tomas@tuxteam.de Newsgroups: gmane.emacs.help Subject: Re: Question about let binding behavior Date: Tue, 8 Oct 2024 18:02:47 +0200 Message-ID: References: <88c7526c-b7d9-46f8-8799-5825b97d20ba@protonmail.com> <8fc2872f-dded-4713-9937-61c3af974538@protonmail.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="dpQcmlQ22i1PouS4" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26305"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs@gnu.org To: Louis-Guillaume Gagnon Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Oct 08 18:03:19 2024 Return-path: Envelope-to: geh-help-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 ) id 1syCgB-0006b8-El for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 08 Oct 2024 18:03:19 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1syCfo-0003tA-Qg; Tue, 08 Oct 2024 12:02:56 -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 ) id 1syCfl-0003lj-Dc for help-gnu-emacs@gnu.org; Tue, 08 Oct 2024 12:02:54 -0400 Original-Received: from mail.tuxteam.de ([5.199.139.25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1syCfj-0005aU-5e for help-gnu-emacs@gnu.org; Tue, 08 Oct 2024 12:02:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tuxteam.de; s=mail; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject :Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=ZwWV4o1pI10Da8GCVDdjr8MHODuMw5UpDrRXjs7dcsQ=; b=R6sT+udd3jbgOpqwkUgC8bLKNi yjWX0H6gGkWqQ6SID48SiI/jYZ1xZkwrn5IUfRYWYB20OyzBoBqIc/TX7dpfhHCrj014xoWuwjYKh JKdliYwfyI32yrsSfSOtLcDVR+BDhBoezIAdZkF8ce9LIyMVMNrnCxsx1FR4CVA9cU94qJdGAjlmy Ct7Cs1PifurFhsPlXrjRWnHmcrTDH0kFyZZdwArm/zxmFzYOBOC2YPKv2awyO+YyMolLljOhE35BR +gfR0XYEQA/zQyzY7RmMDyyOxxVfAodULCHXJIiXODQscvvqKBz72+2XQr0D/cVlOVMDX4x7Xapk8 pwiZGq/g==; Original-Received: from tomas by mail.tuxteam.de with local (Exim 4.94.2) (envelope-from ) id 1syCff-0007MS-Hj; Tue, 08 Oct 2024 18:02:47 +0200 Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=5.199.139.25; envelope-from=tomas@tuxteam.de; helo=mail.tuxteam.de 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, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:148135 Archived-At: --dpQcmlQ22i1PouS4 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Oct 08, 2024 at 10:05:16AM +0200, tomas@tuxteam.de wrote: > On Tue, Oct 08, 2024 at 07:49:25AM +0000, Louis-Guillaume Gagnon wrote: > > Hi Tomas, > >=20 > > Le 10/8/24 =C3=A0 8:41 AM, tomas@tuxteam.de a =C3=A9crit=C2=A0: > > > The binding (i.e. the "thing" linking the symbol baz to the value > > > '(...) is local. But what you do with that (setcdr... ) is to change > > > the value itself. Your function returns this (possibly changed) value. > > That makes sense, but I guess I'm more surprised that the list itself i= s=20 > > only evaluated a single time -- I would naively have expected for the= =20 > > list to be created anew every time the function is called but that's=20 > > evidently not what's happening. >=20 > Oh. It is a constant (well, technically speaking "a literal" -- constant > has other meanings around here). This is another rabbit hole :-) Actually, the Emacs Lisp manual has a thorough explanation for that ("Lisp Data Types > Mutability") Here's an excerpt, but the whole section is worth a read: 2.9 Mutability =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 Some Lisp objects should never change. For example, the Lisp expression =E2=80=98"aaa"=E2=80=99 yields a string, but you should not change its co= ntents. And some objects cannot be changed; for example, although you can create a new number by calculating one, Lisp provides no operation to change the value of an existing number. =20 Other Lisp objects are =E2=80=9Cmutable=E2=80=9D: it is safe to change= their values [...] =20 If a program attempts to change objects that should not be changed, the resulting behavior is undefined: the Lisp interpreter might signal an error, or it might crash or behave unpredictably in other ways.(1) =20 When similar constants occur as parts of a program, the Lisp interpreter might save time or space by reusing existing constants or their components. For example, =E2=80=98(eq "abc" "abc")=E2=80=99 return= s =E2=80=98t=E2=80=99 if the interpreter creates only one instance of the string literal =E2=80=98"abc= "=E2=80=99, and returns =E2=80=98nil=E2=80=99 if it creates two instances. Lisp programs= should be written so that they work regardless of whether this optimization is in use. Cheers --=20 t --dpQcmlQ22i1PouS4 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABECAB0WIQRp53liolZD6iXhAoIFyCz1etHaRgUCZwVXnwAKCRAFyCz1etHa Rnb/AJ9robZV13tFu5O6zebjlP3lvGDscwCfX5fsvKJ/wUJQ1pn45wLx2gx60Ho= =SGey -----END PGP SIGNATURE----- --dpQcmlQ22i1PouS4--