Search                        Top                                  Index
HELP WHICH                                          A. Sloman May 1983

    which(variables, patternlist) -> list of values;

WHICH is used in conjunction with the DATABASE or LIB SUPER. It makes a
list of the values of the variables for each instance of the patternlist
found in the database, using FOREVERY to find all the instances.

When there is only one variable whose values are to be found, then the
corresponding WORD may be given as first argument. If there is more than
one, then the words must be in a list. E.g. the following formats are

    vars x y z;
    which("x", [[parent tom ?x]]) =>
    ** [lucy dick]

    which([x z], [[parent ?x ?y][parent ?y ?z]]) =>
    ** [ [tom harry] [tom mary] [lucy albert] ]

Note that if the first argument to WHICH is a list of words, then the
result is a list of lists. If the first argument is a word, the the
result is a list of values (which may be lists).

-- EXAMPLE USING LIB SUPER --------------------------------------------------

We can give lib super some information about what is on what, and how to
reason about what is above what, thus:

                     [ on a b]
                     [ on b c]
                     [ on e f]
                     [ on f g]
                     [ on h g]
             [ifneeded [above ?x ?y] [on ?x ?y]]
             [ifneeded [above ?x ?y] [on ?x ?z] [above ?z ?y]]

Now we can use WHICH to answer questions. Note that the second argument
must be a list of lists:

     vars x y;
     which("x", [[on ?x g]])=>
     ** [f h]

     which([x y], [[on ?x ?y]])=>
     ** [[a b] [b c] [e f] [f g] [h g]]

     vars z;
     which([x z], [[above ?x ?y][above ?y ?z]])=>
     ** [[a c] [e g]]