all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: "'Xue Fuqiao'" <xfq.free@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: RE: About self-referential object
Date: Fri, 4 Jan 2013 16:55:56 -0800	[thread overview]
Message-ID: <3FC0BF0CCCB24BA6820F98E685943F9A@us.oracle.com> (raw)
In-Reply-To: <20130105082439.6fd039019e3ffaee66477208@gmail.com>

> Emacs detects such recursion and prints `#LEVEL' instead of 
> recursively printing an object already being printed.  For 
> example, here `#0' indicates a recursive reference to the 
> object at level 0 of the current print operation.
> 
> But I don't understand.  What does `object at level 0 of the 
> current print operation' mean?

It starts to print the object `foo', which is a cons cell whose car is the value
of `foo' and whose cdr is ().  To print the cons cell it prints `(', followed by
the car, followed by `)' - since the cdr is ().

Let's assume first that it tries to print the infinite object without any
abbreviation.  When it starts printing the value of `foo' it is at level 0 (top
level).  When it tries to print the car of that cons, it needs to print the
value of `foo' again, this time at printing level 1: `((foo))'.  When it tries
to print that third `foo' it is at level 2, and so on.  Think of the printing
"levels" here as recursive calls to a printing function.

To abbreviate, it prints just (#0), meaning a single cons cell with, as its car,
the same cons cell, i.e., the object that the printer started out to print.

Printing it the long way would be impossible.  But it would also be misleading
(incorrect), because we would naturally read `(((...(foo)...)))' as being a cons
cell with a different cons cell as its car, and that cons cell having another
cons cell as its car,... etc.

IOW, we would read it incorrectly as nested cons cells, all of which are
different.  In fact, there is only one cons cell, whose car is itself.

Pascal correctly mentioned the _read_ syntax for this kind of thing: #1=(#1#).
If you try to read the printed value #0 then an error is raised.

See also (elisp) `Circular Objects'.




  reply	other threads:[~2013-01-05  0:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-04 23:32 About self-referential object Xue Fuqiao
2013-01-04 23:47 ` Drew Adams
2013-01-05  0:24   ` Xue Fuqiao
2013-01-05  0:55     ` Drew Adams [this message]
2013-01-05  1:26       ` Xue Fuqiao
2013-01-05  0:27   ` Xue Fuqiao
     [not found] ` <mailman.16720.1357343280.855.help-gnu-emacs@gnu.org>
2013-01-05  0:07   ` Pascal J. Bourguignon
2013-01-08 16:06     ` Stefan Monnier
     [not found] <mailman.16719.1357342389.855.help-gnu-emacs@gnu.org>
2013-01-04 23:40 ` Pascal J. Bourguignon

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=3FC0BF0CCCB24BA6820F98E685943F9A@us.oracle.com \
    --to=drew.adams@oracle.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=xfq.free@gmail.com \
    /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.