Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

The LISP

Name: Anonymous 2010-10-12 9:18

Why is the function car not called first-of?

Why is the function cdr not called last-of?

Because.... post a comment with the answer, faggot.

Name: Anonymous 2010-10-12 9:39

car isn't first and cdr isn't last.

In Common Lisp, you have synonyms for car and cdr called first and rest.

car and cdr are just accessors (readable and writable, although this is CL specific) for the 2 fields of the cons structure. Chains of conses make lists (proper or improper). The end of a proper list is marked by a NIL (or also known as '(), the empty list), such that the cdr (cdr points to the /rest/ of the list, while car points to the current/top element of the list) of the last cons in the list is NIL. When you're using chains of conses as lists (and for all intents and purposes, you don't need to use car/cdr to access them at all - there are more specific functions for operating on lists), it might make sense to use first/rest synonyms instead of car/cdr, so that you would be more clear that you're working on lists and not on plain conses (which are nothing more than pairs of 2 values, and can be used as such, for representing all kinds of data which fit the bill).

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List