Open ChimeraCoder opened 12 years ago
tested cons car and cdr.. working
Closing this issue.
Reopening for the same reason that I'm reopening the others - a clean checkout of testing
still doesn't run the tests properly, so I can't test that they're working homoiconically (beyond simply working properly).
Lists of arbitrary length shouldn't (technically) be implemented natively. Really, all we have are cons cells, which look like the following:
and are created with the cons function
All that
car
andcdr
do are access the first and second elements of a cons cell, respectively. In this case, those would be x and y. However, the second element can be a reference to another cons cell, which means that we get(cons x (cons y z))
or(x . (y . z))
or(x y z)
which are all equivalent.
The fact that there are no lists of arbitrary length - just cons-cells of length two, which may happen to be chained together to simulate lists, actually helps make other functions simpler to implement (because you never have to worry about how to handle variable length. All you have to do is write the base case (cell has two literal elements) and the recursive case (cell has a literal first element and the second element points to another cell), and everything will Lisp-magically take care of itself).
Let's make sure we're consistent with these everywhere, because that will help us make this much simpler to implement than if we're inconsistent with our implementation.