this_module(?atom, ?quoted_atom, ?atom)

The built-in predicate this_module/3 gives information about the compiled module in which it resides. The predicate will fail if it is called outside a module.

The first parameter is the name of the currently loaded module, the second parameter is the filename of the module and the last parameter is the open-mode of the module (read or readwrite). Information about a module is unified with each parameter.

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.

see also: active_module/1 check_singleton/1 close_all_modules/0 close_module/1 consult/0 consult/1 consult/3 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_search/3 open_standard_module/2 save_module/1 save_module/2 save_module/3 set_active_module/0 set_active_module/1

Examples
test_clause :-
  do_something,
  this_module(Name, File, Mode),
  ...
If this clause is placed inside a compiled module then it succeeds and unifies its parameters with the name, file name and open mode of the module containing the predicate test_clause/0
test_clause :-
  do_something,
  this_module(test_module, File, read),
the goal this_module/3 succeeds if it is placed inside a module with the name 'test_module' and that was opened with the open mode 'read'

 

Exceptions
an argument Arg is not an atom nor a variable a type_error(atom, Arg) exception is thrown
there is no module with the same name a existence_error(module, A) exception is thrown

 

 

info@trinc-prolog.com