From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Newsgroups: gmane.emacs.help Subject: Re: Question about let binding behavior Date: Tue, 8 Oct 2024 08:41:42 +0200 Message-ID: References: <88c7526c-b7d9-46f8-8799-5825b97d20ba@protonmail.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="DmbcahFge1u/5O3o" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27851"; 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 08:42:27 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 1sy3vP-000767-8o for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 08 Oct 2024 08:42:27 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sy3um-0004M4-Kf; Tue, 08 Oct 2024 02:41:48 -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 1sy3ul-0004Lp-Hd for help-gnu-emacs@gnu.org; Tue, 08 Oct 2024 02:41:47 -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 1sy3uj-0005K7-IW for help-gnu-emacs@gnu.org; Tue, 08 Oct 2024 02:41:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tuxteam.de; s=mail; h=From:In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To: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=6Ve/kAhE13BVFREQGMBjKURBOwRpFkWIpsBCtxRQpH4=; b=G4YB1vBWwNmrsOryxLLZpk9ULk QgG4QyRwqiYVzhEpFlFoSiVms66m5tci64Jpnajh2RBvS7o1pfxXFwob8zHehRxP4eAFq63VDAfxn Hwxi5y8V5uPh+I7wsIVFMZ4kGnatDdP2tOgSQ5lLM4xp0I4oYJhSQlvzCPDepgZVLp2feLr9acav0 dspzJe+FyA+4hBuv1np14WaTFwBS8Aclg35R1eVsQ8oVEVjKtAu+tUD+GR4Qr506tIMAHKIG3NJ+y jSJQMh6bnmM+zftShIcLVdSZORE7deSnpXOFo+/m5zyxIit26zM581X2NUDQqNyYSYAfVIttyxgB5 SArm48Xg==; Original-Received: from tomas by mail.tuxteam.de with local (Exim 4.94.2) (envelope-from ) id 1sy3ug-0005ZT-6C; Tue, 08 Oct 2024 08:41:42 +0200 Content-Disposition: inline In-Reply-To: <88c7526c-b7d9-46f8-8799-5825b97d20ba@protonmail.com> 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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:148130 Archived-At: --DmbcahFge1u/5O3o Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Oct 08, 2024 at 06:21:03AM +0000, Louis-Guillaume Gagnon wrote: > Dear all, >=20 > I'm a long time user but I've only recently started to dive into elisp=20 > programming. I'm a bit surprised by the following behavior. >=20 > Let's say I write the following silly function: >=20 > (defun foo (bar) > =C2=A0 (let ((baz '((quux . 0) (quuz . 0)))) > =C2=A0=C2=A0=C2=A0 (if (> 10 bar) > =C2=A0=C2=A0=C2=A0 (setcdr (assoc 'quux baz) bar) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (setcdr (assoc 'quuz baz) bar)) > =C2=A0=C2=A0=C2=A0 baz)) >=20 > Then the following evals: >=20 > (foo 1) > =3D> ((quux . 1) (quuz . 0)) >=20 > (foo 100) > =3D> ((quux . 1) (quuz . 100)) >=20 > I'm surprised that the list is not reset since I thought the binding was= =20 > local to the function, but clearly I don't have the right mental model=20 > for elisp evaluation. 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. Lisps have a different "accent" than more pure functional languages, where values are more immutable. > For the actual application I ended up using=20 > copy-tree but I'd like to understand this better -- could someone=20 > explain or point out the relevant sections of the manual? Did that help? Cheers & enjoy Lisp :-) --=20 tom=C3=A1s --DmbcahFge1u/5O3o Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABECAB0WIQRp53liolZD6iXhAoIFyCz1etHaRgUCZwTUHwAKCRAFyCz1etHa RkxNAJ9sVMJQFvQNZExajQMIqxTf9pG50ACaA8kqCqJ15ztu9KvpHQhsK14sxy0= =KncR -----END PGP SIGNATURE----- --DmbcahFge1u/5O3o--