all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Nicolas Richard <theonewiththeevillook@yahoo.fr>
To: help-gnu-emacs@gnu.org
Subject: Re: How does letf work?
Date: Wed, 29 Jan 2014 16:06:27 +0100	[thread overview]
Message-ID: <87txcmq13g.fsf@yahoo.fr> (raw)
In-Reply-To: <slrnlehfeo.6e2.joost.m.kremers@j.kremers4.news.arnhem.chello.nl> (Joost Kremers's message of "29 Jan 2014 08:37:45 GMT")

Joost Kremers <joost.m.kremers@gmail.com> writes:
> I suspect what is going on is that what is returned by the letf (and
> cl-letf) is not the value of the symbol test-x (which I've kinda assumed
> up until now), but a pointer to the object test-x is referring to (i.e.,
> the first cons cell of the list).

How I understand it is : what is returned by the letf *is* the value of
the symbol, but since it is a cons cell it can be modified by setf
(using setcar and setcdr). So part of the job of letf is to *change* the
cons cell upon exiting. The box is the same (and is what is returned),
but the content was changed at the moment the last closing paren of letf
is crossed. IOW:

(defvar test-x '(KEY 1 2 3 4))

(letf (((cdr test-x) '(a b c d)))
  (copy-sequence  test-x))
=> (KEY a b c d)

but

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


Returning (copy-sequence test-x) instead of
test-x will produce the expected value.

> 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.

The object is the same, but its content changed. Similar to :
(let ((foo (cons 'a 'b))
      (bar))
  (setq bar foo) ;; bar and foo have the same object in their value cell.
  (setcdr foo 'c) ;; change the cdr of that cons cell
  (eq bar foo)) ;; they're still the same.
=> t

> 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

I guess it's not gone per se until the garbage collector does its work.

-- 
Nico.



  parent reply	other threads:[~2014-01-29 15:06 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
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 [this message]
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=87txcmq13g.fsf@yahoo.fr \
    --to=theonewiththeevillook@yahoo.fr \
    --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.