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

Serious Question

Name: Anonymous 2007-09-25 12:35 ID:iAJ5jp/N

What the fuck is CDR anyway?

Name: Faggy McFagFag 2007-09-25 15:52 ID:Dkqab+kY

>>1
In Scheme (and Lisp in general), there exists a structure called the cons cell, which contains two values or pointers to values. car returns the first item in a cons cell. cdr returns the second item in a cons cell.
(car (cons 1 2)) => 1
(cdr (cons 1 2)) => 2

More importantly, cons cells are used to implement singly linked lists. The list structure is defined recursively; any list structure in Lisp is either:
1. An empty list, usually called nil and represented as '().
2. A cons cell whos car is the first element of the list and whose cdr is a smaller list containing the rest of the elements.
You can see that when dealing with lists, car returns the "head" of the list, and cdr returns the "tail" of the list.

I hope I helped you understand cdr :).

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