Quintus Prolog Manual


(PREV) (NEXT)

k-1: Introduction

k-1-1: Directory Structure

The Quintus Prolog Library directory (part of the installation directory described in {manual(a-1)}) includes six subdirectories which contain files written in Prolog and C which supplement the Quintus Prol kernel:

library
contains a large number of predicates which can be regarded as extensions to the set of predicates which are built into the Prolog system. Both source and QOF versions are provided.
tools
source files for Quintus-supplied development tools, independent programs which perform various functions such as determinancy checking and cross-referencing. They can be used to analyze your programs statically (that is, without running them) and possibly locate bugs.
protalk
an object-oriented package written in Prolog. The directory includes documentation and examples.
structs
contains the structs library package which allows access to C/Pascal data structures from Prolog. The directory includes demos.
IPC
two inter-process communication packages: Remote Predicate Call (RPC) and Transmission Control Protocol (TCP).
embed
modules for user customization of message handler. See {manual(g-20)}.
english
default message handler; basis for translation.
swedish
translated message handler, messages in Swedish.
quintus.h
C header file. This is an include file which contains #defines, typedefs, struct definitions, etc., which are needed to compile C code which needs to call Quintus provided functions or use Quintus data structures. During installation, this file is copied to /usr/include/quintus/quintus.h. If for some reason you cant find /usr/include/quintus/quintus.h, you can always use the copy in the 'embed' directory instead.

The predicate library_directory/1 has predefined clauses for the library and tools directories. These depend on the file_search_path/2 definition of qplib. You can see these clauses by typing "listing." or "listing(library_directory)." after starting up Prolog. This definition of library_directory/1 means that you can refer, from within Prolog, to any file in any of these areas using the form library(File). For example either (A) or (B) would load the file lists.qof from the 'library' directory.

        | ?- [library(lists)].                     (A)



        | ?- load_files(library(lists)).           (B)



Library packages are typically loaded by doing (C) if the package is not a module-file or if it is a module and you want all the exported predicates.

        | ?- ensure_loaded(library(add_portray)).  (C)



See the descriptions of ensure_loaded/1 and use_module/[1,2,3]. You will notice that the library name 'add_portray' includes an underscore. Some file systems do not permit underscores in file names. The 'library(_)' wrapper exists, in part, to decouple library names from file names, and Quintus Prolog will remove the underscores if necessary. Use absolute_file_name/[2,3] to find out the actual filename of any library package. In addition to the loadable QOF files, source files (.pl or .c) are provided for each package.

k-1-2: Status of Library Packages

The predicates described here have been tested and are believed to work as documented. If you want something slightly different from one of these predicates, it is strongly recommended that you do not change the existing definition. Instead, write a new predicate using the existing definition as a model. There are several reasons for not changing the definition of a predicate in the library:

  1. It may confuse people reading your code who are familiar with the documented behavior of the library predicate.
  2. If you use other library files, they may depend on the exact definition of this predicate.
  3. You might have to redo your modification if you wished to run your program on some new release of Quintus Prolog.
  4. Quintus does not accept responsibility for any bugs introduced by a user's change to library code.

k-1-3: Documentation of Library Packages

All library packages include code comments, often extensive, which serve as documentation. Accessing these comments and other information available in the library directory is discussed in {manual(k-1-3-1)}. In addition, many packages are more fully documented:

The rest are abstracted in {manual(k-12)}. For these the information in the following section is particularly useful.

k-1-3-1: Accessing Code Comments

If you know the name of the library package in question, simply look at the source code in qplib3.3. Apart from code comments, there is information about predicates in two files which summarize the contents of the directory. They are called Contents and Index. If you do not know the name of the package the Index file will be helpful. If you know the name of the package, you can use the Contents file to gain further information about it. The Index file contains one line for each exported predicate in the library. The predicates are listed in standard order, ignoring module names. A typical entry looks like this:

        list_to_binary/4   flatten   ./flatten.pl



This means that there is a predicate called list_to_binary/4 in the library, that it lives in a module called 'flatten', and that the file which contains it is 'flatten.pl' in the same directory as the Index. If you have set up an "environment variable" QL holding the name of the Quintus library directory, you could ask "what predicates are there to deal with files?" by issuing the UNIX command

        % egrep files $QL/Index



The Contents file is organized by library files rather than by predicates. A typical entry in this file is a block of lines like this:

        basics  + documented in manual

        basics  % the basic list processing predicates

        basics  - ./basics.pl

        basics  : member/2

        basics  : memberchk/2

        basics  : nonmember/2



The first line means that library(basics) is one of the library packages which is fully documented in this manual. The second line is a short description of the contents. The third line says which file contains library(basics); in this case it is 'basics.pl' in the same directory as Contents. The remaining lines list the predicates exported by library(basics). You could obtain this information by issuing the UNIX command

        % egrep '^basics' $QL/Contents



These files are provided as a convenience, and do not have the same authority as the printed manual.

k-1-4: Notation

k-1-4-1: Character Codes

Many of the examples in this manual show lists of character codes being written as quoted strings. This actually happens if you load the library package library(print_chars). That package extends the predicate portray/1 (using library(add_portray)) so that print/1, the top-level, and the debugger will write lists of character codes as follows:

        | ?- X = [0'a,0'b,0'c].

        X = [97,98,99]



        | ?- ensure_loaded(library(print_chars)).



        | ?- X = [0'a,0'b,0'c].

        X = "abc"



k-1-4-2: Mode Annotations

A new system of representing the modes of arguments has been adapted in Release 3, is described in {manual(l)}. The library, including IPC, is still documented under the old system of mode annotations: Each predicate definition is headed by a goal template such as

        setof(?X,+Goal,-Set)



Here X and the others are meta-variables which name the arguments so that we don't have to keep saying "its first argument" and so on. The characters which precede the meta-variables will seem familiar if you know the mode declarations of DEC-10 Prolog; their significance is as follows:

+
This argument is an input to the predicate. It must initially be instantiated or the predicate fails and sends an error message to the standard error stream.
-
This argument is an output. It is returned by the predicate. That is, the output value is unified with any value which was supplied for this argument. The predicate fails if this unification fails. If no value is supplied, the predicate succeeds, and the output variable is unified with the return value.
?
This argument does not fall into either of the above categories. It is not necessarily an input nor an output, and it need not be instantiated.

Note that it is not an error to call a predicate with a '-' argument already instantiated. The value supplied will simply be unified with the result returned, and if that unification fails, the predicate fails.


Copyright (C) 1997 AI International Ltd
contact: product support sales information