help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about let binding behavior


From: tomas
Subject: Re: Question about let binding behavior
Date: Tue, 8 Oct 2024 18:02:47 +0200

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,
> > 
> > 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 :-)

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
  ==============
  
  Some Lisp objects should never change.  For example, the Lisp expression
  ‘"aaa"’ yields a string, but you should not change its contents.  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.
  
     Other Lisp objects are “mutable”: it is safe to change their values
  [...]
  
     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)
  
     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, ‘(eq "abc" "abc")’ returns ‘t’ if the
  interpreter creates only one instance of the string literal ‘"abc"’, and
  returns ‘nil’ if it creates two instances.  Lisp programs should be
  written so that they work regardless of whether this optimization is in
  use.

Cheers
-- 
t

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]