MATCHES is a Pop-11 procedure which takes two arguments, a list and a pattern (which is also a list), and produces one result, a boolean, i.e. either TRUE or FALSE. The name of the procedure "matches" is defined to be an infix operator (like "=", "+", "<>" and "::") so that it can be used in the form
list matches patternIt takes two arguments, both lists, and returns one result, a boolean. The first argument is called the DATUM (what is given) and the second the PATTERN, against which the datum is to be compared.
The pattern may contain special pattern elements, of which "==" is a simple example. Other types of pattern elements are explained below. Notice the asymmetry: the pattern must be the second argument, never the first.
To illustrate, here is a procedure which uses MATCHES to decide whether a question requires a person or a place as its answer:
define type_of_answer(list) -> type; if list matches [who is ==] then "person" -> type elseif list matches [where is == ] then "place" -> type else "undef" -> type endif enddefine;The procedure type_of_answer takes as its input a list, and produces a word as its result. The word is one of "person" "place" "undef". Notice the use of the multi-branch conditional form:
if condition1 then action1 elseif condition2 then action2 else default action endifAn expression using "matches" can be used as a condition because it always produces a boolean result. We can test the above definition thus:
type_of_answer([who is your father]) => ** person type_of_answer([where is your father]) => ** place type_of_answer([is Joe your father]) => ** undef"undef" is a word often used in in Pop-11 to indicate something unknown.
Of course, this definition is not at all adequate to recognizing requests for information about persons or places, e.g.
type_of_answer([where was joe born]) => ** undefThe matching procedure MATCHES is used by the database procedures ADD, REMOVE, PRESENT, LOOKUP, and FLUSH and the database looping constructs FOREACH and FOREVERY, about which more is said below. These provide very useful problem-solving tools for both AI programming and other kinds of programming requiring manipulation of complex, changing structures.