Doc needs help
You can actually also pass a series of files (is this inofficial? The argument just says :File
. Note that the mode indicator :
indicates a meta-predicate argument, i.e. File
would be a goal. That makes no sense, File
is just a file.
?- consult([foo,roo]).
If you use
[user].
The code entered will be added to the special user
module. See: Reserved Modules and using the‘user' module
Consult always succeeds
Even if the file to load has errors- It is then loaded partly.
For this file:
child_of(joe, ralf). child_of(mary, joe child_of(steve, joe).
Consult it:
?- [test]. ERROR: /home/paquette/java/test.pl:2:20: Syntax error: Operator expected true. ?- child_of(X,Y). X = joe, Y = ralf.
What if I want to transactionally succeed/fail when loading a file and know whether the loading succeeded? 🤔
Module files aren't special
You can also load modules using consult/1 or [Module1,Module2]
instead of using use_module/1 or use_module/2.
Reload loaded files that have changed on-disk
Use make/0 to reconsult changed files.
Edge case
If there are files "roo", "foo", "foo.pl
" and "foo.pl
.pl"
Then
[foo].
loads "foo.pl
".
['foo.pl'].
or
["foo.pl"].
also load "foo.pl
"
['foo.pl.pl'].
loads "foo.pl
.pl"
Loading file "foo" is not possible, but
[roo].
still loads "roo"
It is only the suffix ".pl" which is processed this way. If the suffix is not ".pl", you cannot leave the suffix out in the argument to consult. This is relevant for files containing plunit unit test code, which are supposed to end in '.plt'.
Loading unit test files
At plunit, we read:
"Test-units can be embedded in normal Prolog source-files. Alternatively, tests for a source-file can be placed in another file alongside the file to be tested. Test files use the extension .plt. The predicate load_test_files/1 can load all files that are related to source-files loaded into the current project."
There is no direct support for files ending in .plt via [consult], you have to write
?- ['foo.plt']
On the other hand, once you have read a `.pl` file then you can use load_test_files/1:
?- load_test_files([]).
will read the files names the same way only with `.plt` extension.
After that, you can run the test code in the .plt files with
?- run_tests.
Encoding of source files
See this:
In particular, this source file should be loadable without problems:
citation :- писатель(1,Author), цитирование(1,Citation), format("Author: ~s~nCitation: ~s~n",[Author,Citation]). % Facts! писатель(1,"Р.П.Уоррен"). цитирование(1,"Ты должна сделать добро из зла, потому что его больше не из чего сделать.").