Next: Action Sequences, Previous: Type Declarations, Up: Programs [Contents][Index]
An interpreter relation query is a Complex Conjunction.
This has the form:
Cond1 &
Cond2 & ... &
Condn, n>=1
where each condi is one of:
(
Exp1,...,
Expk), k>=0
,
where each Expki is an expression - a term that may contain function calls and
RelExp is an expression returning a k-ary relation rel’ such that the values of the argument expressions will satisfy the mode and type constraints of rel’ when it is called. Certain binary primitive relations, for example =,=?,in
, can be written with tghe relation name between the arguments.
not (exists
VarSeq SConj )
negated condition,
where VarSeq is a sequence of local variables of SConj which is a Simple Conjunction. This is the QuLog negation-as-failure operator.
call Var
, Var
a variable, relation meta-call.
(..)
bracketed Simple Conjunction, prefixed with once
- find one solution only
forall
UVars (exists
EVars1 SConj1 =>
exists
EVars2 SConj2 )
The UVars variables are universally quantified over the implication. The sequence of variables of EVarsi
are existentially quantified over SConji, i=1,2
. Each SConji is a Simple Conjunction.
A Simple Conjunction is a Complex Conjunction which does not contain any forall
In a negated condition the existentially quantified variables are local variables of SConj, variables that do not appear elsewhere in the query or rule body in which the negation appears. All other variable of SimpleConj, except underscore anonymous variables, must be given ground values before the condition is evaluated. Underscore variables are always implicitly existentially quantified just before the predication in which they appear.
If there are no such local variables the exists
VarSeq is absent.
The type of call
is
call: rel(!relcall)
.
relcall
is the system type comprising all terms that denote type correct calls to primitive or program defined relations. For the relcall
type the !
mode has a special meaning. It does not mean that Var
has to be a ground term. It means only that all input arguments of the type declaration of the relation named by the functor of its compound term value must be ground. This is often guaranteed by preceding the meta call with the type test type(Var,!relcall)
.
In a forall
, each variable in UVars must appear in both SimpleConj1 and SimpleConj2. It must be a local variable of the forall
. All other variables of the forall
, except the existentially quantified variables and underscore variables, must have ground values when the forall
condition is evaluated. Each EVarsi contains variables local to
SimpleConji.
If there are no existentially quantified variable, for either the antecedent or consequent, the exists
operator is dropped.
Suppose we have a collection of child_of(C, P)
, age_is
and male
dynamic relation facts. The following query will
return as an answer each parent who only has male children age over 17.
child_of(_, P) & forall C (child_of(C,P) => exists A (male(C) & age_is(C,A) & A>17))
Note that P
will be given a value before the evaluation of the forall
, as required.
Next: Action Sequences, Previous: Type Declarations, Up: Programs [Contents][Index]