all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: tomas@tuxteam.de
To: Louis-Guillaume Gagnon <gagnonlg@protonmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Question about let binding behavior
Date: Tue, 8 Oct 2024 10:05:16 +0200	[thread overview]
Message-ID: <ZwTnvBSZy3I9ejo8@tuxteam.de> (raw)
In-Reply-To: <8fc2872f-dded-4713-9937-61c3af974538@protonmail.com>

[-- Attachment #1: Type: text/plain, Size: 1348 bytes --]

On Tue, Oct 08, 2024 at 07:49:25AM +0000, Louis-Guillaume Gagnon wrote:
> Hi Tomas,
> 
> Le 10/8/24 à 8:41 AM, tomas@tuxteam.de a écrit :
> > 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 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.

Oh. It is a constant (well, technically speaking "a literal" -- constant
has other meanings around here). This is another rabbit hole :-)

But -- either someone else chimes in, or it'll have to wait till the
afternoon, since I'm at $DAYJOB at the moment.

The short answer is that it's usually a good idea to use "fresh" storage
when you plan to mutate the (innards of the) "thing".

Some Lisps enforce literal immutability. Some others do funny things.

I.e. some moral equivalent of

  (let ((foo (cons (cons one 1) (cons two 2)))) ...)

(of course you may use some deep-copy function or similar).

The fun part is that you get to choose at which depth you plan in
immutability :-)

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

  reply	other threads:[~2024-10-08  8:05 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-08  6:21 Question about let binding behavior Louis-Guillaume Gagnon
2024-10-08  6:41 ` tomas
2024-10-08  7:49   ` Louis-Guillaume Gagnon
2024-10-08  8:05     ` tomas [this message]
2024-10-08 16:02       ` tomas
2024-10-09  8:01         ` Louis-Guillaume Gagnon via Users list for the GNU Emacs text editor
2024-10-09  8:13           ` Tomas Hlavaty
2024-10-09 23:39             ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-10-10  7:58               ` Tomas Hlavaty
2024-10-10 18:38                 ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-10-18 11:25                   ` Rudolf Schlatte
2024-10-08  8:15     ` Joost Kremers
2024-10-08 22:27       ` Michael Heerdegen via Users list for the GNU Emacs text editor
2024-10-08 22:21     ` Michael Heerdegen via Users list for the GNU Emacs text editor
2024-10-08 15:47 ` [External] : " Drew Adams
2024-10-09  2:28 ` Stefan Monnier via Users list for the GNU Emacs text editor
  -- strict thread matches above, loose matches on Subject: below --
2024-10-09  8:34 Louis-Guillaume Gagnon via Users list for the GNU Emacs text editor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZwTnvBSZy3I9ejo8@tuxteam.de \
    --to=tomas@tuxteam.de \
    --cc=gagnonlg@protonmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.