3 ms·
You are mistaken. In Lisp, lists are constructed out of NIL and dotted pairs, so, (1 . (2 . (3 . NIL))) = (1 2 3) I chose to implement lists in Python in th
by DonaldFisk 10y ago
You are mistaken. In Lisp, lists are constructed out of NIL and dotted pairs, so,
(1 . (2 . (3 . NIL))) = (1 2 3)
I chose to implement lists in Python in the same way, out of () and 2-element tuples. So
(1 2 3) = (1 . (2 . (3 . NIL))) in Lisp which becomes (1, (2, (3, ())) in Python.
(cdr '(1 2 3)) = (2 3) = (2 . (3 . NIL)) which should therefore be (2, (3, ())) in Python, i.e. the second element of the 2-element tuple (1, (2, (3, ())), NOT the 1-element tuple
((2, (3, ())),) obtained by removing the first element.
I should point out that there is one difference, in case anyone else spots it: tuples in Python are immutable, whereas dotted pairs in Lisp are not, so my implementation won't allow rplaca and rplacd.
- deleted 10y ago[deleted]