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

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

RE: About self-referential object


From: Drew Adams
Subject: RE: About self-referential object
Date: Fri, 4 Jan 2013 16:55:56 -0800

> 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 via email to

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