From: Joost Kremers <joost.m.kremers@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: How does letf work?
Date: 29 Jan 2014 09:14:38 GMT [thread overview]
Message-ID: <slrnlehhju.6e2.joost.m.kremers@j.kremers4.news.arnhem.chello.nl> (raw)
In-Reply-To: slrnlehfeo.6e2.joost.m.kremers@j.kremers4.news.arnhem.chello.nl
Joost Kremers wrote:
> And since the printing is done outside the letf, as you pointed out, the
> object that's printed is the one pointed to by the global binding of
> test-x. But that's not because outside the letf the object created
> inside it is necessarily gone. It's gone because letf doesn't return a
> pointer to it. If it does, the object can stay around longer, as
> demonstrated by returning the (cdr test-x).
[Apologies for the reply-to-self...]
This account also explains why the OP's code with setf works the way it does:
(let ((x (copy-list test-x)))
(setf (cdr x) '(a b c d))
x)
=> (KEY a b c d)
Because let creates a new binding (for x), a new pointer is created.
With copy-list, a new object is created to which this binding points.
After modifying the cdr of that object, the pointer is returned.
Outside the let, the binding for x is gone but the pointer to the object
it referred to is still alive, so the object itself is also kept alive
(until it's been printed).
--
Joost Kremers joostkremers@fastmail.fm
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)
next prev parent reply other threads:[~2014-01-29 9:14 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-28 23:10 How does letf work? Florian Beck
2014-01-29 2:23 ` Michael Heerdegen
[not found] ` <mailman.13075.1390962244.10748.help-gnu-emacs@gnu.org>
2014-01-29 8:37 ` Joost Kremers
2014-01-29 9:14 ` Joost Kremers [this message]
2014-01-29 15:29 ` Florian Beck
2014-01-29 16:12 ` Nicolas Richard
2014-01-29 20:19 ` Florian Beck
2014-01-29 15:06 ` Nicolas Richard
2014-01-29 23:46 ` Michael Heerdegen
2014-01-29 23:53 ` Michael Heerdegen
[not found] <mailman.13065.1390951154.10748.help-gnu-emacs@gnu.org>
2014-01-29 0:35 ` Emanuel Berg
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=slrnlehhju.6e2.joost.m.kremers@j.kremers4.news.arnhem.chello.nl \
--to=joost.m.kremers@gmail.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.