Pattern Matching

Given a pattern and an input, matching must:

  1. Test whether the input matches the pattern. A common convention is to let pattern variables begin with `` ?''.

  2. Keep variable bindings: for each pattern variable, the corresponding input.

Consider the example:

Pattern:      (- ?x (- ?y))

Input:        (- (sin theta) (- w))
The input matches the pattern; the bindings should be:

 ( (?x . (sin theta))
   (?y . w) )
This format is called an association list, or alist. The form ( x . y) , called a dotted pair, is produced by (cons x y) .

Contents    Page-10    Prev    Next    Page+10    Index