PLOGHELP USES                                Robert Duncan, January 1988

A "once-only" library mechanism.


    :- library(useful).

    ?- uses(Pred).


This goal is similar to the goal

    ?- library(Pred).

(see PLOGHELP * LIBRARY) in that it will search for (and reconsult) a
file called 'Pred.pl' in a list of standard library directories. The
extra feature provided by uses/1 is that it will first check by means of
a call to current_predicate/2 whether there is already an existing
definition of a predicate with functor name -Pred- and will not load the
library file if so. This is on the assumption that the predicate was
defined by a previous call to library/1 or uses/1 on that same file and
therefore that the file doesn't need loading again.

This means that a call to uses/1 can be placed in several places in a
program (for example, in separate files which may or may not be loaded
together) and only the first call encountered will have any effect.

This only works if the library file defines a predicate of the same name
as itself. Without that it is not possible to tell whether a particular
file has already been loaded or not. Certain of the standard libraries
do have this property (library "gensym" for example) but not all.

If you wish to use this feature with your own library files but find
cases where a file doesn't naturally define a predicate of exactly the
same name, you can always add a dummy definition to the end of the file
exclusively for this purpose. For example, in a file 'myshell.pl' which
defines your own expert systems shell, you could append the lines

    ;;; Dummy definition for uses/1
    myshell.

which defines the predicate myshell/0 purely so that the directive

    :- uses(myshell).

will take action only the first time it is encountered.


uses/1 is itself a library predicate defined in LIBRARY USEFUL.


-- RELATED DOCUMENTATION ----------------------------------------------

PLOGHELP * CURRENT_PREDICATE
    Tells which predicates are currently defined.

PLOGHELP * LIBRARY
    How to access library files and how to create your own libraries.

PLOGHELP * USEFUL
    A library of useful predicates.

--- C.all/plog/help/uses -----------------------------------------------
--- Copyright University of Sussex 1988. All rights reserved. ----------
