7.1 Introduction

This section contains descriptions of the functions, relations and actions of the QuLog library. In the interpreter you can see all their names and types by entering the command

| ?? stypes.

This listing is included in Listing of Builtin Types.

Many of these are Qu-Prolog primitive relations ’lifted’ to QuLog by giving them appropriate type/mode declarations. Other Qu-Prolog relations and actions can be ’lifted’ to the QuLog level be giving them a QuLog type declaration in our QuLog program file.

For example, if the primitives described in List Processing had not already been made available for use in QuLog, all we would have needed to do was include their type declarations as given in that section.

As another example, there is a Qu-Prolog primitive

between(From,To,N)

for generating or testing an integer value N between given integer values From and To.

To use this in a QuLog program, we add the moded type declaration

rel between(int,int,?int)

to our program file. It tells the QuLog mode/type checker that the relation is a Qu-Prolog primitive (that will be checked), and that in every use the first two arguments should be given as integers but the third integer argument may be given or may be returned as value of an unbound variable.

Sometimes we might want to lift a QuProlog relation or action to the QuLog level and we want to use the same name but the QuProlog definition requires some modification. For example, an existing QuProlog definition for an action might contain choicepoints or might fail. In both cases some modification to the code is required.

The way this can be accomplished is to define a variant of the code at the QuProlog level and a mapping between the QuProlog and QuLog code as in the following simple example.

In this example we want to lift gmtime to the QuLog level as a relation that uses the same name. The second argument of gmtime is a compound term whose functor is time. We decide that, at the QuLog level, we would prefer to use time_ as the functor.

To do this we first write the required QuProlog code in, for example, lift_eg.ql:

%% define the mapping between the QuProlog and QuLog
%% the first argument is the QuLog call and the second is
%% the QuProlog call
?- assert(qulog2qp_map_(gmtime(A, B), gmtime_(A, B))).

gmtime_(A, B) :-
    integer(A), !,
    gmtime(A, time(T1, T2, T3, T4, T5, T6)),
    B = time_(T1, T2, T3, T4, T5, T6).
gmtime_(A, B) :-
    B = time_(T1, T2, T3, T4, T5, T6),
    gmtime(A, time(T1, T2, T3, T4, T5, T6)).

We then write the QuLog code in, for example, lift_eg.qlg:

%% consult the above QuProlog code
?- pconsult(lift_eg).

%% declare the type
def time_t ::= time_(nat, nat, nat, nat, nat, nat)
%% declare the relation
rel gmtime(!nat, ?time_t), gmtime(?nat, !time_t)

When this is consulted the compiler will translate queries or code involving gmtime to gmtime_.

For example, after consulting the file above:

| ?? gmtime(960285920, T).

T = time_(100, 5, 6, 10, 5, 20) : time_t

| ?? gmtime(T, time_(100, 5, 6, 10, 5, 20)).

T = 960285920 : nat

For the relations and actions not given below we refer the reader to the doc strings when using stypes and the QuProlog manual.


On This Site