This predicate can be used for opening a file containing prolog text and loading it into memory (the text is compiled while loading). Each module is identified by an unique name, this name must be supplied as the first argument of this predicate, the expected type of this argument is an atom. The second argument is a filename enclosed by single or double quotes, the third argument is the open-mode of the module or a list of open-options.
The third argument can either be a single open-option or a list of open-options. The available options are:
It is possible to use a relative path name to open a file if open_module/3 is used inside a file that has been compiled. The relative path is combined with the path of the file in which the call to consult/1 resides to load the file specified. When specifying a filename put two backslash characters for each normal backslash in the filename, otherwise the character sequence could be mistaken for a symbolic control character like for instance: \t, which is replaced by a single tab character.
In Trinc-Prolog R3B this built-in predicate was expanded with the possibility that the third argument can be a list of open-options. The open-option 'not_active' was added. The exception 'domain_error(module_mode, A)' was replaced by the exception 'domain_error(consult_option, A)'.
see also: active_module/1 check_singleton/1 close_all_modules/0 close_module/1 consult/0 consult/1 create_module/1 create_module/2 ensure_loaded/1 include/1 module/3 module_name/2 modules open_module/0 open_module/1 open_module/3 open_module_search/3 open_standard_module/2 save_module/1 save_module/2 save_module/3 set_active_module/0 set_active_module/1 this_module/3
| Examples | |
| open_module(m23, "c:\\temp\\st23.txt", readwrite). | open the file "c:\temp\st23.txt" with the open-mode readwrite, the module will be identified by the name m23 and is the active module |
| open_modulet(m23, "c:\\temp\\st23.txt", [read, not_active]). | open the file "c:\temp\st23.txt" with the open-mode read,, the module will be identified by the name m23 and does not become the active module |
| open_module(23, "c:\\temp\\st23.txt", read). | the first argument is not an atom so a type_error(atom, 23) exception is thrown |
| open_module(m23, 'xx:\\tdde\\st3.txt', read). | because the file doesn't exist an existence_error(module_file, 'xx:\tdde\st3.txt') exception is thrown |
| Exceptions | |
| any of the arguments is a empty variable | instantiation_error |
| one or both of the first and third arguments are not an atom | type_error(atom, A) |
| the second argument is not an atom enclosed by single or double quotes | type_error(atom_doublequoted, A) |
| the second argument is an atom not enclosed by single quotes | type_error(atom_singlequotes, A) |
| Invalid open-option specified | domain_error(consult_option, A) |
| the same file is already open or there is already a module with the same name | existence_error(module, A) |
| the file cannot be opened | existence_error(module_file, A) |
| one or more errors found in the module being opened | compile_error(module, A), A is replaced by the internal of the module |