From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Joost Kremers Newsgroups: gmane.emacs.help Subject: Re: Question about let binding behavior Date: Tue, 08 Oct 2024 10:15:11 +0200 Message-ID: <86r08r57u8.fsf@fastmail.fm> References: <88c7526c-b7d9-46f8-8799-5825b97d20ba@protonmail.com> <8fc2872f-dded-4713-9937-61c3af974538@protonmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33773"; mail-complaints-to="usenet@ciao.gmane.io" Cc: tomas@tuxteam.de, 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 10:15:54 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 1sy5Np-0008cN-Ou for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 08 Oct 2024 10:15:54 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sy5NQ-0005ZM-2F; Tue, 08 Oct 2024 04:15:28 -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 1sy5NJ-0005YB-P8 for help-gnu-emacs@gnu.org; Tue, 08 Oct 2024 04:15:21 -0400 Original-Received: from fhigh-a5-smtp.messagingengine.com ([103.168.172.156]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sy5NG-00081I-QC for help-gnu-emacs@gnu.org; Tue, 08 Oct 2024 04:15:20 -0400 Original-Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfhigh.phl.internal (Postfix) with ESMTP id AEE251140300; Tue, 8 Oct 2024 04:15:15 -0400 (EDT) Original-Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Tue, 08 Oct 2024 04:15:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.fm; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1728375315; x=1728461715; bh=NKXHJLhEnZ 9wOpFFmzt9TgVj7TMHXcPFspD4m7o+0zI=; b=APVvQ3fV8MxcETAWdp5wJ8p29A dd3GSdlKM28kSM9jXEfpFKa/WItR03H+FTRxyPOgqIHd4M9cWDzK4dgO6Fc/pggK xZ0tDEjaf3uI5OFDm9ttOBoXIzgze1xKHvKh8/xt0N8J/CUplnZmxmbcIPDgVZRs qMrguvhGm7vIdmgAwPzXekClmSlJFkDrdTpEx/nIMIcq6gIEeDDor7+yKD8YvUgs BpYDANhts3oQjl6TfhmwalLCjouYUp/dxhKd4Q7w3hpEX9nlKaSUj/IhJ1E+FbFw d456gibRFFHBRR7RxmhNwTc8kV/CVQUj7QBOLE41M7ev3hdT8oTbFABUhUJg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1728375315; x=1728461715; bh=NKXHJLhEnZ9wOpFFmzt9TgVj7TMH XcPFspD4m7o+0zI=; b=PUhh4FvXSNURPr3Hk1Mp6ArJfp5bqHiE9odETAr1OEsh qzCwkl7pkirzDDpStdClxacWDtpPn9/QwRFW2tXQ69EXqdqdKi+dUX7BUnd+BLVF eqT6k3ROFqqcNWWDiYbJ+qeaz1FmF6LKhPLfchXSTpkocNR9TP9LekUeCyVpCmOr bAYNm0Q+hBkc38482ku02M05NL+FczPi9d4IhG8q+/pPdLDFqE0JyHPtGd2BTLFK oX+DHaiHP40+tNGRmODBZSna8CnJUTCN4gcrsxD9FNTzAITW6mhj/uJTw1p4cfUj HBDe5ksPWfZX8TEifAh+5zqzBeEFA87KdM4Vswn6mw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdefuddgtdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephffvvefujghffffkgggtsehttdertddttddtnecu hfhrohhmpeflohhoshhtucfmrhgvmhgvrhhsuceojhhoohhsthhkrhgvmhgvrhhssehfrg hsthhmrghilhdrfhhmqeenucggtffrrghtthgvrhhnpeekveelieeuleettdefueegvddu kefhgeevleduveeileetkeeggfekhfeuffffieenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpehjohhoshhtkhhrvghmvghrshesfhgrshhtmhgr ihhlrdhfmhdpnhgspghrtghpthhtohepfedpmhhouggvpehsmhhtphhouhhtpdhrtghpth htohephhgvlhhpqdhgnhhuqdgvmhgrtghssehgnhhurdhorhhgpdhrtghpthhtohepthho mhgrshesthhugihtvggrmhdruggvpdhrtghpthhtohepghgrghhnohhnlhhgsehprhhoth honhhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: ie15541ac:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 8 Oct 2024 04:15:13 -0400 (EDT) In-Reply-To: <8fc2872f-dded-4713-9937-61c3af974538@protonmail.com> (Louis-Guillaume Gagnon's message of "Tue, 08 Oct 2024 07:49:25 +0000") Received-SPF: pass client-ip=103.168.172.156; envelope-from=joostkremers@fastmail.fm; helo=fhigh-a5-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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:148133 Archived-At: On Tue, Oct 08 2024, Louis-Guillaume Gagnon wrote: > That makes sense, but I guess I'm more surprised that the list itself is > only evaluated a single time -- I would naively have expected for the > list to be created anew every time the function is called but that's > evidently not what's happening. The reason for that is that the list is a constant: the literal list is part of the code, and the object is created when the defun is evaluated. The object will stick around, even if the binding to it (baz) is local to the function. Now, what I honestly don't know is if the object can at some point be garbage-collected, but I suspect it can. I wouldn't bet on it staying around, anyway. If you don't want the object to stick around, make sure you create it in the function: ``` (defun foo (bar) (let ((baz (list (cons 'quux 0) (cons 'quuz 0)))) (if (> 10 bar) (setcdr (assoc 'quux baz) bar) (setcdr (assoc 'quuz baz) bar)) baz)) ``` -- Joost Kremers Life has its moments