Next: Simple Conditions for Rules and Relation Queries, Previous: Type Definitions, Up: Programs [Contents][Index]
All functions, relations, actions and teleoR programs have type declarations of the form
Name :
Type
Examples of declarations are given below where definitions are described.
If multiple functions, relations, actions or teleoR programs have the same type their names can all be listed on the left hand side of a declaration as follows.
Name1, ..., NameN :
Type
As an example, below is the type declaration for the builtin append
relation (with the same semantics as the standard Prolog append relation).
append : (![T], ![T], ?[T]) <= | (?[T], ?[T], ![T]) <= | (![T?], ![T?], ?[T?]) <= | (?[T?], ?[T?], ![T?]) <= | ([T]?, [T]?, [T]?) <=
The first type of append
says that, if the first two arguments
of the call on append
are ground lists of a given type, then the third argument will be a ground list of the same type on exit from the call.
The second type says that, if the third argument is a ground list of a given type, then the first and second arguments will be ground lists of the same type on exit from the call.
The third type of append
says that, if the first two arguments are lists
of a known length (i.e. do not have a variable tail) but possibly containing non-ground elements, then
the third argument will have a known length on exit from the call but that
variables occurring in any of the arguments need not be ground.
The fourth type is the "append driven backwards" version of the third type.
The fourth type is the most general allowing variable length lists in all arguments. In this situation, nothing can be said about the modes on exit from the call.
Note that when we say, for example, the first two arguments are of the same type we mean that the type inference system can find a suitable type as in the example interpreter query below.
| ?? append([1,2], [a,b], X). X = [1, 2, a, b] : [atom || nat]
Here, the suitable (minimal) type for T
is the union of two types.
Beliefs are dymanic relations and are declared as follows.
belief
Name1 : ArgTypes1 , ...,
NameN : ArgTypesN
Where each ArgTypesI is of the form
(TE1,TE2,...,TEk)
in which each TEi
is any simple, or compound type name, or type union expression, or a code type expression.
The declaration
belief age_of: (human,age)
is esentially the declaration
age_of : (?human, ?age) <=
together with the declaration that age_of
is dynamic.
Percepts are similar to beliefs in that they are dynamic but are specifically used for storing percepts in teleoR programs. They are declared as follows.
percept
Name1 : ArgTypes1 , ...,
NameN : ArgTypesN
Global variables are used to store either integer or number values and are declared as follows.
int
Name :=
IntValue
or
num
Name :=
NumValue
The declaration
int count := 0
is like a combination of the declaration
belief count : (int)
and the definition
count(0)
with the restriction that the count
belief always contains exactly
one fact.
Next: Simple Conditions for Rules and Relation Queries, Previous: Type Definitions, Up: Programs [Contents][Index]