next up previous contents
Next: LIB FMATCHES overcomes Up: CHAPTER.7: THE POP-11 Previous: Checking a set

Forevery: simultaneously satisfying a collection of patterns

Just as ALLPRESENT is a generalisation of PRESENT, so Pop-11 includes FOREVERY which is a generalisation of FOREACH, and allows some fairly powerful manipulations of the database. In particular, we can find all possible combinations of a SET of patterns in the database. E.g. to find all paternal grandfather relations, i.e. all combinations of the form

    [?x father ?y][?y father ?z]
Here's an example

    [
        [dick father harry]
        [tom father jack]
        [bill father tom]
        [dick father mary]
        [jack father dick]] -> database;

    vars x, y, z;
    forevery [[?x father ?y] [?y father ?z]] do
        [^x is the paternal grandfather of ^z] =>
    endforevery;
    ** [tom is the paternal grandfather of dick]
    ** [bill is the paternal grandfather of jack]
    ** [jack is the paternal grandfather of harry]
    ** [jack is the paternal grandfather of mary]
Note that FOREVERY made sure that whatever matched "y" in in the two patterns was the same.

The permitted formats of FOREVERY are:

    FOREVERY <list of patterns> DO <actions> ENDFOREVERY;

    FOREVERY <list of patterns> IN <database> DO <actions> ENDFOREVERY;
When `IN <database>' is omitted, then the value of the variable DATABASE is used as the database.

Another example: find all the blocks and print out their colours:

    forevery [[?x isa block] [colour ?x ?col]] do
        [^x is a ^col block] =>
    endforevery;
Or to find all maternal grandfather relationships:

    forevery [[?x father ?y] [?y mother ?z]] do
        [^x is grandfather of ^y] =>
    endforevery;
In addition to these procedures the Pop-11 library contains some more powerful procedures SCHECK and SCHOOSE, for matching a whole database pattern against a database, and indicating whether the match was partially successful, what was missing, what was surplus, etc. For details see TEACH SCHEMATA

A powerful expert system shell based on the matcher is described in HELP NEWPSYS, and TEACH PSYSRIVER

Although the database procedures described here are very powerful compared with what most programming languages provide. They are still not as powerful as the facilities built into the language Prolog. See, for example:

    W. Clocksin and C.S. Mellish
    PROGRAMMING IN PROLOG, Springer Verlag.


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