In lisp languages, when the reader encounters something like (non-list1 . non-list2)
it returns it as a “cons” cell, whose “car” is non-list1
, and its “cdr” is non-list2
.
Let's now consider the syntax (non-list . list)
. In this case the result of reading this s-expression can be seen again as a “cons” cell with non-list
as “car”, and with list
as “cdr”, but this is exactly the definition of a list which has its first element non-list
, and the rest of its elements list
.
So, for instance, (2 . ())
is read as (2)
, which is list that has 2
has its first element, and no other elements (so the rest of the list is the empty list, ()
). Analogously, (1 . (2 . ()))
is read as (1 2)
, and so on.
So, in your example, the syntax (equal? . 8)
is returned by the reader as a cons cell with two atoms, a symbol and a number, and this is not a valid expression to be evaluated (remember that in lisp languages one can evaluate only lists with the first element the “operator” (function, macro, etc.), and the rest of the list as its arguments).
Let's now consider the second expression, and try to see if it is a list which is a valid expression to evaluate.
(equal? . ((quote . ((a . (b . (c . ()))))) . ('(a b c))))
The part (a . (b . (c . ())))
is simply the list (a b c)
. So, we have now:
(equal? . ((quote . ((a b c))) . ('(a b c))))
Remember that the syntax 'something
is equivalent to (quote something)
and vice-versa, we have now:
(equal? . ((quote (a b c)) . ('(a b c))))
and then:
(equal? . ('(a b c) . ('(a b c))))
let's interpret the rightmost dot:
(equal? . ('(a b c) '(a b c)))
and finally:
(equal? '(a b c) '(a b c))
which is a valid expression to evaluate. And remembering that 'X
is the datum X
, here we are comparing two lists (a b c)
that are equal according to the predicate equal?
.