next up previous contents
Next: FOREACH: iterates over Up: CHAPTER.7: THE POP-11 Previous: Retrieving values from

Using LOOKUP to extract information from the database

We do not always want to know what the matching item was. Sometimes we will know in advance that an item matching the pattern is present in the DATABASE and want only the value of some fragment of the item.

For this purpose the procedure LOOKUP is provided. It does not return <TRUE> or <FALSE> but merely sets the value of queried pattern variables when a match is found, and causes an error if no match is found.

    alladd([[a b c d] [d c b a] [a b d c]]);

    lookup([= ?x b ==]);
    x =>
    ** c
In the event of no match being found an error will result

    lookup([?x == e]);
    ;;; MISHAP - LOOKUP FAILURE
    ;;; INVOLVING:  [? x == e]
    ;;; DOING    :  sysprmishap mishap lookup ......
Note that PRESENT is to MATCHES as LOOKUP is to -->. PRESENT and MATCHES check a condition and return a true/false result, and may simultaneously bind pattern variables. But only PRESENT searches over a list. LOOKUP and --> do not return any result, and only LOOKUP searches.

    procedure   returns           iterates over       mishap on
                a boolean         the database        failure
    ---------------------------------------------------------
    matches      yes                   no               no
    -->          no                    no               yes
    present      yes                   yes              no
    lookup       no                    yes              yes


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