[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How does letf work?
From: |
Nicolas Richard |
Subject: |
Re: How does letf work? |
Date: |
Wed, 29 Jan 2014 17:12:48 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
Florian Beck <fb@miszellen.de> writes:
>
> (letf* ((x (copy-list test-x))
> ((cdr x) '(a b c d)))
> x)
>
> => (KEY 1 2 3 4)
>
> I'm still confused.
test-x, which I recall is (KEY 1 2 3 4) here, is simply a cons cell. Its
car is KEY, its CDR is (1 2 3 4).
After the first line of the letf*, test-x and x are different cons
cells. In fact their CAR are `eq', and their CDR are not. OTOH nothing
of this is relevant, test-x doesn't matter here.
After the second line, you changed the CDR of x to the list '(a b c d).
But that is a temporary binding that'll be reverted as soon as we exit
the letf* form.
At the third line, before the closing paren, you say: return the value
of x, so you indeed get that cons cell, which is '(KEY a b c d).
But now, the closing paren happens, i.e. letf* does its job and reverts
the variable value of x to what is was before (empty, I presume, making
x an unbound symbol) and the place represented by (cdr x), i.e. the cdr
of the cons cell that just got returned, to its initial value: '(1 2 3
4). So when letf returns, the cons cell that we received changes. And
that's what gets printed.
--
Nico.