So far we've described our patterns in very literal terms. i.e. that there needs to be a "B" and a "D", or a list etc. In practice the items we want to include in our specification may have been constructed by other procedures (and as we shall see by procedures that use MATCHES). Typically these items will be the value of variables.
Suppose we have a variable "box" whose value is a list representing the contents of a box.
vars box = [shoes tins brushes] ;And a variable cupboard corresponding to a cupboard that contains the box and other things:
vars cupboard = [[shoes tins brushes] blanket hats coats umbrellas];If we write
cupboard matches [box blanket ==] => ** <false>The result is false because the first element of cupboard is not the word "box" but a list which is the same as the value of the variable box. We need to enrich the pattern specification language so as to distinguish between words used literally and words used as variable names. We do this with the up-arrow
^
prefix, as explained in the
chapter on lists. Thus
cupboard matches [^box blanket ==] => ** <true>The use of
^
(up-arrow) in the pattern specification here is
the same as that introduced earlier. Thus
[box blanket ==] => ** [box blanket ==]But
[^box blanket ==] => ** [[shoes tins brushes] blanket ==]And it is of course only this latter version that matches CUPBOARD.