GNU Emacs Lisp Reference Manual, 2.8 Equality Predicates:
Comparing circular lists may therefore cause deep recursion that leads to an error, and this may result in counterintuitive behavior such as
(equal a b)
returningt
whereas(equal b a)
signals an error.
I've found a case:
ELISP> (setq a '#1=(t . #1#)
b `(t t . ,a))
ELISP> (equal b a)
t
ELISP> (equal a b)
*** Eval error *** List contains a loop: #1=(t . #1#)
ELISP>
Does Elisp test eq
first when testing equal
?
If so, I don't think (equal a b)
will signal an error.
I mean,
a: t ---
^ |
| |
----
b: t -> t -> t ---
^ | This loop is `a`.
| |
----
when testing whether a
eq
s b
:
a
andb
are not the same obj (i.e. noteq
)- so test their first element, and
t
eq
st
; then test their CDRs a
's CDR andb
's CDR are not the same obj- so test CDRs' first element, and
t
eq
st
; then test CDRs' CDRs a
eq
sa
so I think (equal a b)
should return t
.
Where is my mistake?