next up previous contents
Next: Two Variations on Up: Interactive Program Development Previous: Interactive Program Development

A Problem with consult/1

Consider the query:

 ?-  consult([foo1,foo2]).

where both foo1 and foo2 contain clauses for, say, baz/1. We get the following:

The procedure baz/2 is being redefined.

Old file: /u/user5/ai/staff/paulb/

New file: /u/user5/ai/staff/paulb/

Do you really want to redefine it? (y, n, p, or ?) ?

Therefore, as far as is possible, avoid splitting your predicate definitions between files.

The command reconsult(foo) is equivalent to consult(foo). The command reconsult(foo) can be rewritten as [-foo] and the command reconsult([foo1,foo2]) can be rewritten as [-foo1,-foo2].

Some Prolog systems distinguish these commands. For these systems, the command consult([foo1,foo2]) has the consequence of loading the syntactically correct clauses found both in foo1 and in foo2 ---if they share the definition of baz/2 then both parts of the definition will be loaded.

Finally, if you really have to distribute your predicate definitions between files with a command like consult([foo1,foo2]) then there must be a declaration that the predicate is a multifile predicate before SICStus encounters the first clause. So, if baz/2 is shared between files, we need to place

:- multifile baz/2.

before the first clause for baz/2.

Even though mostly you won't need to do this, there are occasions when it does make sense to distribute a predicate across several files.

Paul Brna
Mon May 24 20:14:48 BST 1999