One of the datatypes Arc supports is binary trees, built out of cons cells. A standard technique in Lisp is to build a binary tree with data at the leaves and cons cells as the interior nodes.


For example, the above balanced tree is expressed as ((1 . 2) . (3 . 4)), which is normally displayed as ((1 . 2) 3 . 4).


The tree does not need to be balanced, for instance, the above tree is (((1 . 2) . 3) . 4).

Arc provides a few operations on binary trees. However, Arc provides no explicit support for generating binary trees. The primitive cons can be used to join two nodes or subtrees into a tree. The primitives car and cdr will return the left and right subtrees (or nodes) respectively.

arc> (= mytree (cons (cons 1 2) (cons 3 4)))
((1 . 2) 3 . 4)
arc> (car mytree)
(1 . 2)
arc> (cdr mytree)
(3 . 4)
arc> (cadr mytree)
3
For more information on cons-cell binary trees, see Wikipedia.