next up previous contents index
Next: Fill matrix Up: Programming Concepts Previous: Group   Contents   Index

Subsections

Lookup

Description

The lookup concept is used to convert data stored in the local database into a list of terms that can be manipulated in the program. The most natural template (first argument of findall) is to use the same term as for the facts in the database.

Parameters

Res
a free variable, will be bound to a list

Schema

:-mode lookup(-).
lookup(Res):-
        findall(q(X),q(X),Res).

Comments

findall examplifies a typical meta-predicate, the second argument is actually a goal that will be executed. There are a number of other predicates of this type, and this feature can be extremely useful in writing interpreters, emulators etc, which treat data as program parts.

The findall predicate is significantly faster than bagof or setof. Their use is not recommended.


Example

% find all hops routing information
:-mode gather_hops(-).
gather_hops(Hops):-
        findall(hop(A,B,C),hop(A,B,C),Hops).



Warwick Harvey
2004-08-07