Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Definition of a Lisp Cons Cell?

What exactly is the definition of a Common Lisp Cons Cell? How is a Cons Cell different than a standard linked list item? After all, both the cons cell and the linked list item have a value and a pointer to the next cell or item... or is this understanding wrong?

like image 557
λ Jonas Gorauskas Avatar asked Aug 22 '09 20:08

λ Jonas Gorauskas


2 Answers

Cons cells in general hold two pointers that can point to anything. General usage of course is to point to a "value" with the left one, and to another Cons cell (or nil) with the "right" one.

like image 88
Zed Avatar answered Oct 02 '22 16:10

Zed


A cons cell is closer to a binary tree node than a linked list node. car and cdr return the two children, which can be nil, atoms, or other cons cells.

like image 35
Jim Lewis Avatar answered Oct 02 '22 16:10

Jim Lewis