What is the difference between how cons works on the following two items:
(cons 1 '(2))
; (1 2)
(cons 1 2)
; (1 . 2)
Both evaluate pair? to true, so I'm curious how the two are different.
Does one produce:
--------
| 1 | 2 |
-------
And the other produces:
-------- --------
| 1 | -> | | 2 | X |
------- -------
Or what's the difference?
You need to understand how a proper list is defined in Scheme. A proper list is created by
consing elements, where thecdrpart is either anotherconscell or the empty list'(). The first example in the question is a proper list:Of course we can also create arbitrary
conscells that don't follow the rule. The second example in the question demonstrates this, it's aconscell where thecdrpart is not anotherconscell or the empty list, hence it's not a proper list: