* About self-referential object @ 2013-01-04 23:32 Xue Fuqiao 2013-01-04 23:47 ` Drew Adams [not found] ` <mailman.16720.1357343280.855.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 9+ messages in thread From: Xue Fuqiao @ 2013-01-04 23:32 UTC (permalink / raw) To: help-gnu-emacs I have a question about self-referential object: (setq foo '(nil)) => (nil) (setcar foo foo) => (#0) It is an infinite recursion. What does the `#0' mean here? Can anybody help? Thanks. -- Best regards, Xue Fuqiao. http://www.emacswiki.org/emacs/XueFuqiao ^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: About self-referential object 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:27 ` Xue Fuqiao [not found] ` <mailman.16720.1357343280.855.help-gnu-emacs@gnu.org> 1 sibling, 2 replies; 9+ messages in thread From: Drew Adams @ 2013-01-04 23:47 UTC (permalink / raw) To: 'Xue Fuqiao', help-gnu-emacs > (setq foo '(nil)) => (nil) > (setcar foo foo) => (#0) > > It is an infinite recursion. What does the `#0' mean here? The Elisp manual is your friend. There are no doubt several ways to look this up. Start with `i' usually, which uses the indexes. If you don't find what you want using `i' then try searching: `C-s #0' finds an answer immediately in this case, in node `Output Function'. If you can find what you want by means other than using the indexes (`i'), consider reporting an Emacs bug to improve the index, explaining how you tried to find it. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: About self-referential object 2013-01-04 23:47 ` Drew Adams @ 2013-01-05 0:24 ` Xue Fuqiao 2013-01-05 0:55 ` Drew Adams 2013-01-05 0:27 ` Xue Fuqiao 1 sibling, 1 reply; 9+ messages in thread From: Xue Fuqiao @ 2013-01-05 0:24 UTC (permalink / raw) To: Drew Adams; +Cc: help-gnu-emacs On Fri, 4 Jan 2013 15:47:42 -0800 "Drew Adams" <drew.adams@oracle.com> wrote: > The Elisp manual is your friend. There are no doubt several ways to look this > up. Start with `i' usually, which uses the indexes. I've used > If you don't find what you want using `i' then try searching: `C-s #0' finds an > answer immediately in this case, in node `Output Function'. Sorry for not mentioning my preparation for this question(and other questions). Before I ask a question, I usually try these methods: 1. Search the archives of comp.emacs and gnu.emacs.help. 2. Search on the web. 3. Use `icicle-Info-index'. 4. Use `icicle-search' on the manuals flattened with `Info-merge-subnodes'. 5. Search the Emacs FAQ. 6. Read the source code(but I'm not an Emacs Lisp guru). I had found it in (info "(elisp) Output Functions"), it says: 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? > If you can find what you want by means other than using the indexes (`i'), > consider reporting an Emacs bug to improve the index, explaining how you tried > to find it. Thanks for your advice. I'll do that the next time. -- Best regards, Xue Fuqiao. http://www.emacswiki.org/emacs/XueFuqiao ^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: About self-referential object 2013-01-05 0:24 ` Xue Fuqiao @ 2013-01-05 0:55 ` Drew Adams 2013-01-05 1:26 ` Xue Fuqiao 0 siblings, 1 reply; 9+ messages in thread From: Drew Adams @ 2013-01-05 0:55 UTC (permalink / raw) To: 'Xue Fuqiao'; +Cc: help-gnu-emacs > 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'. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: About self-referential object 2013-01-05 0:55 ` Drew Adams @ 2013-01-05 1:26 ` Xue Fuqiao 0 siblings, 0 replies; 9+ messages in thread From: Xue Fuqiao @ 2013-01-05 1:26 UTC (permalink / raw) To: Drew Adams; +Cc: help-gnu-emacs On Fri, 4 Jan 2013 16:55:56 -0800 "Drew Adams" <drew.adams@oracle.com> wrote: > 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. Ah, I see, thanks. -- Best regards, Xue Fuqiao. http://www.emacswiki.org/emacs/XueFuqiao ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: About self-referential object 2013-01-04 23:47 ` Drew Adams 2013-01-05 0:24 ` Xue Fuqiao @ 2013-01-05 0:27 ` Xue Fuqiao 1 sibling, 0 replies; 9+ messages in thread From: Xue Fuqiao @ 2013-01-05 0:27 UTC (permalink / raw) To: Drew Adams; +Cc: help-gnu-emacs A typo: no "I've used" in between. -- Best regards, Xue Fuqiao. http://www.emacswiki.org/emacs/XueFuqiao ^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <mailman.16720.1357343280.855.help-gnu-emacs@gnu.org>]
* Re: About self-referential object [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 0 siblings, 1 reply; 9+ messages in thread From: Pascal J. Bourguignon @ 2013-01-05 0:07 UTC (permalink / raw) To: help-gnu-emacs "Drew Adams" <drew.adams@oracle.com> writes: >> (setq foo '(nil)) => (nil) >> (setcar foo foo) => (#0) >> >> It is an infinite recursion. What does the `#0' mean here? > > The Elisp manual is your friend. There are no doubt several ways to look this > up. Start with `i' usually, which uses the indexes. > > If you don't find what you want using `i' then try searching: `C-s #0' finds an > answer immediately in this case, in node `Output Function'. > > If you can find what you want by means other than using the indexes (`i'), > consider reporting an Emacs bug to improve the index, explaining how you tried > to find it. Emacs lisp is really baroque. Why introduce #0 when #1=(#1#) can already denote it? -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: About self-referential object 2013-01-05 0:07 ` Pascal J. Bourguignon @ 2013-01-08 16:06 ` Stefan Monnier 0 siblings, 0 replies; 9+ messages in thread From: Stefan Monnier @ 2013-01-08 16:06 UTC (permalink / raw) To: help-gnu-emacs > Emacs lisp is really baroque. > Why introduce #0 when #1=(#1#) can already denote it? Because the second one came after (IIRC around Emacs-21) the first one. Stefan ^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <mailman.16719.1357342389.855.help-gnu-emacs@gnu.org>]
* Re: About self-referential object [not found] <mailman.16719.1357342389.855.help-gnu-emacs@gnu.org> @ 2013-01-04 23:40 ` Pascal J. Bourguignon 0 siblings, 0 replies; 9+ messages in thread From: Pascal J. Bourguignon @ 2013-01-04 23:40 UTC (permalink / raw) To: help-gnu-emacs Xue Fuqiao <xfq.free@gmail.com> writes: > I have a question about self-referential object: > > (setq foo '(nil)) > => (nil) > (setcar foo foo) > => (#0) > > It is an infinite recursion. What does the `#0' mean here? Can anybody help? Thanks. It means you've commited the sacrilege of modifying a literal value! If you modify a mutable cons cell, everything works as expected: *** Welcome to IELM *** Type (describe-mode) for help. ELISP> (setq print-circle t) t ELISP> (setq foo (cons nil nil)) (nil) ELISP> (setcar foo foo) #1=(#1#) ELISP> -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}. ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2013-01-08 16:06 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 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
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).