next up previous contents
Next: List pattern matching Up: CHAPTER.7: THE POP-11 Previous: Findroom revisited

Setting a value ("?") vs Using a value ("^")

Notice the difference between "?" and "^" here. The searched-for information is represented by the list

    [^name ?len ?breadth ?height]
where the symbol "^" says that the given name must be found. "^" can be read as `use the value of', whereas the occurrences of "?" can be read as `set the value of'. I.e. the three variables will be given values depending on what numbers are found after the name, once the list with the required name is found. If we had used "?name" instead of "^name", then ANY name would have been accepted.

If the MATCHES operation produces the result TRUE, having found what is required then the instruction after `then' is obeyed, which ensures that the output local `data' has an appropriate value, to be returned as the result of the procedure.

If MATCHES cannot find what is required in list, then it produces the result FALSE, and the instruction after `else' is obeyed, causing an error message to be printed out.

Using the fact that "-->" will cause an error when a match fails, we could adopt the even shorter definition:

    define findroom(name, list) -> data;

        ;;; Use vars for pattern variables (with "?")
        vars len, breadth, height;

        list --> [ ==  [^name ?len ?breadth ?height] == ];

        [^name ^len ^breadth ^height] -> data;
    enddefine;


Aaron Sloman
Fri Jan 2 03:17:44 GMT 1998