Contents    Page-10    Prev    Next    Page+10    Index   

Binding Lists

A binding is a correspondence of a name and a value. In Lisp, it is conventional to represent a binding as a cons:
(cons name value ), e.g. (?X . 3); we will use a list, (list name value ), e.g. (?X 3) . We will use names that begin with ? to denote variables.

A set of bindings is represented as a list, called an association list, or alist for short. A new binding can be added by:
(cons (list name value ) binding-list )

A name can be looked up using assoc:
(assoc name binding-list )

(assoc '?y '((?x 3) (?y 4) (?z 5)))
   =  (?Y 4)
The value of the binding can be gotten using second:

(second (assoc '?y '((?x 3) (?y 4) (?z 5))))
   =  4