Previous topic  Top  Next topic  Print this Topic
 

Queries

 

A query can be considered as a special kind of rule with an empty head. The following query asks about all admissible drivers of car74:

?- car74[admissibleDriver -> ?Y].

 

The answer to a query consists of all of the variable bindings of the type that the corresponding ground instance of the rule body is true in the object base. Considering the object base described by the facts and rules of the example from the beginning of this manual, the above query yields the following variable bindings:

?Y = paul

?Y = peter

 

Note that variables in a query may only be bound to individual objects, never to sets of objects, i.e. the above query does not return ?X = {paul, peter}.

However, in the case of a query with a set of ground id-terms at the result position, it is only checked if all of these results are true in the corresponding object base. There may also be additional result objects in the database. With the given object base, all of the following queries yield the answer true.

?- car74[admissibleDriver -> {peter, paul}].

?- car74[admissibleDriver -> {paul, peter}].

?- car74[admissibleDriver -> peter].

?- car74[admissibleDriver -> paul].

 

If we want to know if a set of objects is the exact result of a multi-valued method applied to a certain object, we would need to use negation.

More complex queries can be formulated that also contain arbitrary first-order formulas in the (rule) body: The following query computes the maximum value ?X for which p(?X) holds. The rule body expresses that all ?Y for which p(?Y) (also) holds must be less or equal to the searched ?X.

p(1).

p(2).

p(3).

?- p(?X) AND (FORALL ?Y (p(?Y) --> ?Y <= ?X)).

 

The result will be:

?X = 3.0