9 ms·
The main alternatives, first and rest, don't work as well in my head. I mean, car and cdr give you the structure: struct List { Atom car,
by shakna 10y ago
The main alternatives, first and rest, don't work as well in my head.
I mean, car and cdr give you the structure:
struct List {
Atom car,
struct List* cdr
}
Which also explains why an empty list, '(), is nil.
rest sort of implies the next memory section of the list will always be a list. But that's just not the case with a cons cell.
It is a little odd compared to many modern languages, that a data structure is so exposed to the programmer - but it needs to be. Almost everything you do is impacted by that structure, (well, compiler optimisations aside).
It did catch me by surprise when I first came to the LISPy side of things, but once I understood the basic idea of the structure... There wasn't anything left to understand. It explains half the syntax by itself. Why functions are always the first item in a list, for example. car is a cheaper lookup than cdr.
If instead, we weren't dealing with linked lists, but everything was a vector, with a known size, I could see first and rest as making more sense.