Dear Phil,
I still just don't understand some behavior of Ciao Prolog. That is:
when running the Ciao top level and consulting a module (e.g. library(system)) like ?- use_module(library(system)). , the top level tells me that "module already in executable" (which is obviously not true as I couldn't execute the following command) I can use the clauses of the module like ?- cd('..'). and they just work fine.
The message "module already in executable" is indeed true, the ciaosh executable contains (and uses) that library module (system). The reason why you are not able to call the exported predicates of system is because the "user" module under which the toplevel calls are executed is not importing library(system), unless you make "use_module(library(system))."
But when I consult any own file which only contains one line: ?- use_module(library(system)). (the same as above), the clauses will not work - the module seems to be not consulted!
What is the difference between typing a clause in and consulting it as a file?
The '?-' prefix is used in the toplevel because there goals are executed "on the fly", you are not expected to use it in your code. If you want your code import another module, you need a declaration, that is, start it by ':-' :
:- use_module(library(system)).
Note that this makes that that code imports library(system), but this dos not affect the toplevel imports.
You can also group use_module directives you frequently want issue in the toplevel by putting them in a file (with ':-', not with '?-') and making 'include(mystartupfile)'. Note that if you name this file as .ciaorc and put it in your home directory, it will be included by default. An example of a .ciaorc file would be:
:- use_package(iso). :- use_module(library(system)). :- set_prolog_flag(write_strings, on).
Daniel