From: "Pascal J. Bourguignon" <pjb@informatimago.com>
To: help-gnu-emacs@gnu.org
Subject: Re: About Circular Objects
Date: Tue, 25 Dec 2012 15:51:48 +0100 [thread overview]
Message-ID: <87ip7qxjzv.fsf@kuiper.lan.informatimago.com> (raw)
In-Reply-To: mailman.16090.1356446630.855.help-gnu-emacs@gnu.org
Xue Fuqiao <xfq.free@gmail.com> writes:
> I have a question about the #N# read syntax and #N= syntax. Look at this code:
>
> (progn
> (setq x '#1=(a #1#))
> (eq x (cdr x)))
>
> Why does this code return nil? Isn't the second element the list itself?
No. Try it. (use M-x ielm).
*** Welcome to IELM *** Type (describe-mode) for help.
ELISP> (setq x '#1=(a #1#))
#1=(a #1#)
ELISP> x
#1=(a #1#)
ELISP> (cdr x)
#1=((a . #1#))
ELISP> (eq x (second x))
t
ELISP> (eq x (cadr x))
t
ELISP> (eq x (cdr x))
nil
ELISP>
If you want (eq x (cdr x)), then write:
(setq x '#1=(a . #1#))
instead of:
(setq x '#1=(a #1#))
ELISP> (setq x '#1=(a . #1#))
#1=(a . #1#)
ELISP> (eq x (cdr x))
t
ELISP>
Not all circular structures are circular lists. Even circular lists may
have a stem:
ELISP> (let ((circle '#1=(a . #1#)))
(setq x (list* 'a 'a 'a circle)))
(a a a . #1=(a . #1#))
ELISP> x
(a a a . #1=(a . #1#))
ELISP> (eq (car x) (cadr x))
t
ELISP> (eq (cadr x) (caddr x))
t
ELISP> (eq (caddr x) (cadddr x))
t
and so on ad libitum, but:
ELISP> (eq x (cdr x))
nil
ELISP>
--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.
next prev parent reply other threads:[~2012-12-25 14:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.16090.1356446630.855.help-gnu-emacs@gnu.org>
2012-12-25 14:48 ` About Circular Objects Lars Magne Ingebrigtsen
2012-12-25 14:51 ` Pascal J. Bourguignon [this message]
2012-12-25 8:52 Xue Fuqiao
2012-12-25 14:52 ` Teemu Likonen
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=87ip7qxjzv.fsf@kuiper.lan.informatimago.com \
--to=pjb@informatimago.com \
--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.