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

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

Re: How does letf work?


From: Michael Heerdegen
Subject: Re: How does letf work?
Date: Wed, 29 Jan 2014 03:23:35 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Florian Beck <fb@miszellen.de> writes:

> (letf (((cdr test-x) '(a b c d)))
>   test-x)
>
> = > (KEY 1 2 3 4)

Though paradoxical, it seems right to me.  You return a list that you
modified temporarily, but when the result is printed in the echo area,
the letf has been left and the structure of the list has changed back.

Note that the variable test-x is not shadowed by your letf:

(let ((test-x-before test-x))
  (letf (((cdr test-x) '(a b c d)))
    (eq test-x test-x-before)))

==> t

But it has the expected value at that "point of time":

(letf (((cdr test-x) '(a b c d)))
  (message "%s" test-x))

"(KEY a b c d)"


Here is a similarly paradoxical example without letf:

(setq test-x '(KEY 1 2 3 4))
(let ((old-cdr (cdr test-x)))
  (prog2
      (setf (cdr test-x) '(a b c d))
      test-x ;returned value
    (setf (cdr test-x) old-cdr)))

==> (KEY 1 2 3 4)



Regards,

Michael.




reply via email to

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