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: Florian Beck
Subject: Re: How does letf work?
Date: Wed, 29 Jan 2014 21:19:39 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0

Thank you, I think I got it now.

If I understand correctly, it works like this:

{1} means pointer to cons cell 1; <...> means a shadowed cons cell

Simplified example.

(letf*                ; x undefined
    ((x '(A B))       ; x={1} 1=[A|{2}]  2=[B|()]
     ((cdr x) '(C)))  ;                 <2=[C|()]>
  x                   ; x={1} 1=[A|{2}] <2=[C|()]>
  )                   ; returns {1}, i.e. pointer to cell {1}
                      ; which still point to {2}, but {2}'s
                      ; original value has been restored

Same with car:

(letf*                ; x undefined
    ((x '(A B))       ; x={1}  1=[A|{2}]   2=[B|()]
     ((car x) 'D)     ;       <1=[D|{2}]>
     ((cdr x) '(C)))  ;                   <2=[C|()]>
  x                   ; x={1} <1=[A|{2}]> <2=[C|()]>
  )                   ; returns {1}, but both cons cells have
                      ; been restored

But with setf, setcar, etc., there is nothing to restore:

(letf*                ; x undefined
    ((x '(A B)))      ; x={1} 1=[A|{2}] 2=[B|()]
  (setcar x 'C)       ;       1=[C|{2}]
  x)                  ; returns pointer to {1}, which wasn't
                      ; shadowed, so nothing to restore.

(Obviously, we don't need letf in the last example.)

Right? Let returns the "value of the last form". Straightforward in hindsight.
--
Florian Beck



reply via email to

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