I am trying to use consult/1 in a file but keep getting an error indicating that the predicate is undefined. Do I need to include a module or package in order to use this?
I assume you are trying to do so in a program, not in the toplevel shell. If this is the case, the simplest thing is to include the declaration ":- use_module(library(compiler))." in the module you want to call the predicates and use the predicate use_module/1 to load the file at run time. Predicates loaded in this way has to be called qualified by a _, (as _:mypred(X) ) to avoid undefined predicate warnings. The use_module/1 predicate expects that the file you are loading is a module (start by a ":- module(name,_)." declaration). If you don't want the file to be a module, then you can use the predicate ensure_loaded/1, but then you have to include also a declaration ":- use_module(user, [predicates_to_use])". This is an example which include both methods:
:- module(dl, [t/1,u/1], []).
:- use_module(library(compiler)). :- use_module(user, [y/1]).
t(X) :- use_module(dm), _:x(X). u(X) :- ensure_loaded(du), y(X).
Contents of file dm.pl (in the working directory of the executable):
:- module(dm,_).
x(a).
Contents of file du.pl (in the working directory of the executable):
y(2).
Example interaction:
?- use_module(dl).
yes ?- t(X).
X = a ? ;
no ?- u(X).
X = 2 ?
yes ?-
Daniel Cabeza