#xA
is the exact same as 10
, but when it's printed it's system settings that dictates how a number is to be printed. The reason is that the fixnum doesn't have a base, but the visual representation does. Just as #xA
is the same as 10
, ((1 . 2) . (3 . 4))
is the same as ((1 . 2) 3 . 4)
.
The illusion is that we have lists. In order to do that we display pairs with either nil or a pair as tails differently than pairs that has other values as their tail.. A list (1 2)
is modeled as (1 . (2 . ()))
. The rules are something like this: Whenever the tail is nil or a pair you can omit this pair dot and the first parenthesis of the tail. Apply it recursively and (1 . (2 . ()))
displays as (1 2)
and ((1 . 2) . (3 . 4))
displays as `((1 . 2) 3 . 4).
To make the illusion complete the reader does the reverse so when it reads (1 2)
it creates (1 . (2 . ()))
in memory.
To really be a good Lisp programmer (in any dialect) you need to be able to see the omitted dot and parentheses in (1 2)
. When you do it becomes obvious what you need to do with (a (b c) d)
in order to retrieve c
(It's obviously (cadadr '(a (b c) d))
). When you do master this you'll "see" ((1 . 2) . (3 . 4))
.