Spaces are used to separate list tokens. A.B
is a single token. (A.B)
is a list with a single element. (A . B)
is a cons cell with A
as car and B
as cdr.
A cons cell is a pair of "things" (objects). In your case, these things are symbols, and they are named A
, B
, etc.. The printed representation of such a cell is (A . B)
, for example. This is called "dot notation". The first element is called "car", the second "cdr".
The function cons
creates such a cell. (cons 'a 'b)
thus produces the cell (A . B)
. Note that names are always upcased internally.
This is most likely what your teacher wanted, so ((A . B) . C)
is the correct output, and your code the right answer. This is a cell where the car points to another cell, and the cdr contains C
. That other cell is a cell where the car contains A
and the cdr B
.
By the way, a list is a linear chain of such cons cells, such that the car always holds a value and the cdr points to the rest of the list. The last cdr points nowhere (which is called NIL in Lisp). In dot notation, a list is e.g. (A . (B . (C . NIL)))
. Since lists are important, they can be written shorter like this: (A B C)
. If the last CDR has a value instead of NIL, it is shown in dot notation, e.g. (A . (B . (C . D))))
can be written as (A B C . D)
.