In XSB various aspects of the program state -- information about predicates, modules, clauses, and their object files can all be inspected in ways similar to many Prolog systems. However, because the atom-based module system of XSB may associate structures with particular modules, predicates are provided to inspect these elements as well. The following descriptions of state predicates use the terms predicate indicator, term indicator and current module to mean the following:
Example: usermod:append/3
Example: usermod:append(_,_,_)
Note that due to the dynamic loading of XSB, a module can be current even if it has not been loaded, and that some predicates of that module may not be defined. In fact, a module can be current even if it does not exist. This situation occurs when a predicate is improperly imported from a non-existent module. Despite this, a module can never lose the property of being current.
Note that predicate current_module/1 succeeds for a given module even if that module is not a real module (in the sense taht it does not export any predicates). There are no error conditions associated with this predicate; if its argument does not unify with one of the current modules, current_module/1 simply fails.
It is possible for a current module to have no associated file name (as is the case for modules like "usermod" and "global"), or for the system to be unable to determine the file name of a current module. In both cases, predicate current_module/1 will succeed for this module, while current_module/2 will fail. The system is unable to determine the file name of a given module if that module is not in one of the directories of the search path (see Section 3.4). Once again, there are no error conditions associated with this predicate; if the arguments of current_module/2 are not correct, or Module has no associated File, the predicate will simply fail.
Predicate current_functor/1 comes in two flavours depending on the form of its argument (Predicate_Indicator):
| ?- current_functor(Functor/Arity). |
So, to backtrack through all of the functors of positive arity (function and predicate symbols) that appear in the global modules of the system regardless of whether they are system or a user defined, use:
| ?- current_functor(Functor/Arity), Arity > 0. |
For example, if a predicate foo/2 and and a function symbol foo/1 are defined into module blah, the following query will return:
| ?- current_functor(foo, blah:Term). |
If a module is specified, current_functor/2 succeeds only for those functors (function and predicate symbols) which are defined in that module. Unless the module is one of the global modules, current_functor/2 fails for the predicates which are imported into that module.
On the other hand, the goal:
| ?- current_functor(Name, Term). |
can be used to backtrack through every known term Term in the global modules of XSB's database that has Name as its functor.
Note that the order of term generation is undetermined. Once again, there are no error conditions associated with this predicate; if its arguments are inappropriate, the predicate simply fails.
Like current_functor/1, predicate current_predicate/1 comes in two flavours depending on the form of its argument (Predicate_Indicator).
| ?- current_predicate(Functor/Arity). |
So, to backtrack through all of the predicates defined and loaded in module blah, regardless of whether blah is a system or a user defined module 6.2 , use:
| ?- current_predicate(blah:Predicate). |
In this case Predicate will have the form: Functor/Arity.
To backtrack through all predicates defined and loaded in any current module, use:
| ?- current_predicate(Module:Functor/Arity). |
This succeeds once for every predicate that is loaded in XSB's database.
To find the predicates having arity 3 that are loaded in the global modules of the system, use:
| ?- current_predicate(Functor/3). |
while to find all predicates loaded in the global modules of the system regardless of their arity, use:
| ?- current_predicate(Predicate). |
For example, if predicates foo/1 and foo/3 are defined and loaded into module blah, the following query will return:
| ?- current_predicate(foo, blah:Term). |
If a module is specified, current_predicate/2 succeeds only for those predicates which are defined and loaded in that module. Unless the module is one of the global modules, current_predicate/2 fails for those predicates which are imported into that module.
On the other hand, the goal:
| ?- current_predicate(Name, Term). |
can be used to backtrack through every predicate that is loaded in the global modules of XSB's database.
Note that the order of term generation is undetermined. Once again, there are no error conditions associated with this predicate; if its argument is not what it should be, the predicate simply fails.
A brief description of predicate_property/2 is as follows:
| ?- predicate_property(Pred, loaded). |
Also the following query finds all predicate skeletal specifications that are exported by module blah:
| ?- predicate_property(blah:Pred, exported). |
Currently, the following properties are associated with predicates either implicitly or by declaration (where double lines show property categories, and a predicate can have at most one property of each category).
Property | Explanation |
unclassified | The predicate symbol is not yet classified according |
to this category. This property has various meanings. | |
Usually for exported predicate symbols in system or | |
user defined modules it means that the predicate is | |
yet unloaded (because it has not been used). | |
In global modules it usually means that the predicate | |
is either a function symbol, or an unloaded predicate | |
symbol (including constants). | |
dynamic | The predicate is dynamic. |
loaded | The predicate (including internal predicates) is a |
Prolog predicate loaded into the module in question; | |
this is always the case for predicates in global modules. | |
unloaded | The predicate is yet unloaded into the module |
in question. | |
foreign | The predicate is a foreign predicate. This implies that |
the predicate is already loaded in the system, because | |
currently there is no way for XSB to know that a | |
predicate is a foreign predicate until it is loaded in | |
the system. | |
exported | The predicate symbol is exported by the module in |
question; in other words the predicate symbol is | |
visible to any other module in the system. | |
local | The predicate symbol is local to the module |
in question. | |
imported_from(Mod) | The predicate symbol is imported into the module in |
question from module Mod. | |
spied | The predicate symbol has been declared spied |
(either conditionally or unconditionally). | |
tabled | The predicate has been declared tabled. |
built_in | The predicate symbol has the same Functor and Arity |
as one of XSB's builtin (standard) predicates. |
Finally, since dynamic is usually declared as an operator with precedence greater than 999, writing the following:
| ?- predicate_property(X, dynamic). |
will cause a syntax error. The way to achieve the desired result is to parenthesize the operator like in:
| ?- predicate_property(X, (dynamic)). |
Currently, the following properties are associated with modules implicitly
Property | Explanation |
unloaded | The module (including system modules) though it is |
current, is yet unloaded in the system. | |
loaded | The module (including system modules) is loaded in the |
system; this is always the case for global modules. |
| ?- [user]. |
Predicate listing/0 always succeeds. The query:
| ?- listing. |
is just a notational shorthand for the query:
| ?- listing(X). |
| ?- listing([foo/2, bar, blah/4]). |
If Predicate_Indicator is not a variable, an atom or a predicate indicator (or list of predicate indicators) of the form Name/Arity, predicate listing/1 will simply fail.
In future releases of XSB, we intend to allow the user to specify a predicate indicator of the form Module:Name/Arity as argument of listing/1.
This predicate provides information on a wide variety of features related to how XSB was built, including the compiler used, the compiler and loader flags, the machine and OS on which XSB was built, the release number, the various directories that XSB uses to find its libraries, etc.
To find all features and their values, ask the following query:
| ?- xsb_configuration(FeatureName, Value), fail. |
Here is how xsb_configuration might look like:
xsb_configuration(architecture, 'i686-pc-linux-gnu'). %% configuration is usualy the same as architecture, but it can also %% contain special tags, {\it e.g.}, i686-pc-linux-gnu-dbg, for a verion %% built with debugging enabled. xsb_configuration(configuration, 'i686-pc-linux-gnu-dbg'). xsb_configuration(host_os, 'linux-gnu'). xsb_configuration(os_version, '2.34'). xsb_configuration(os_type, 'linux-gnu'). xsb_configuration(host_vendor, 'pc'). xsb_configuration(host_cpu, 'i686'). xsb_configuration(compiler, 'gcc'). xsb_configuration(compiler_flags, ' -ansi -pedantic -Wall -g'). xsb_configuration(loader_flags, ' -lm -ldl -Wl,-export-dynamic'). xsb_configuration(compile_mode, 'debug'). %% The following is XSB release information xsb_configuration(major_version, '1'). xsb_configuration(minor_version, '9'). xsb_configuration(beta_version, '3'). xsb_configuration(version, '1.9-b3'). xsb_configuration(codename, 'Code Breaker'). xsb_configuration(release_date, date(1998, 10, 17)). %% XSB query evaluation directive xsb_configuration(scheduling_strategy, '(batched)'). %% Support for other languages xsb_configuration(perl_support, 'yes'). xsb_configuration(perl_archlib, '/usr/lib/perl5/i386-linux/5.00404'). xsb_configuration(perl_cc_compiler, 'cc'). xsb_configuration(perl_ccflags, '-Dbool=char -DHAS_BOOL -I/usr/local/include'). xsb_configuration(perl_libs, '-lnsl -lndbm -lgdbm -ldb -ldl -lm -lc -lposix -lcrypt'). xsb_configuration(javac, '/usr/bin/javac'). /* Tells where XSB is currently residing; can be moved */ xsb_configuration(install_dir, InstallDir) :- ... /* User home directory. Usually HOME. If that is null, then it would be the directory where XSB is currently residing. This is where we expect to find the .xsb directory */ xsb_configuration(user_home, Home) :- ... /* Where XSB invocation script is residing */ xsb_configuration(scriptdir, ScriptDir) :- ... /* where are cmplib, syslib, lib, packages, etc live */ xsb_configuration(cmplibdir, CmplibDir) :- ... xsb_configuration(libdir, LibDir) :- ... xsb_configuration(syslibdir, SyslibDir) :- ... xsb_configuration(packagesdir, PackDir) :- ... xsb_configuration(etcdir, EtcDir) :- ... /* architecture and configuration specific directories */ xsb_configuration(config_dir, ConfigDir) :- ... xsb_configuration(config_libdir, ConfigLibdir) :- ... /* site-specific directories */ xsb_configuration(site_dir, '/usr/local/XSB/site'). xsb_configuration(site_libdir, SiteLibdir) :- ... /* site and configuration-specific directories */ xsb_configuration(site_config_dir, SiteConfigDir) :- ... xsb_configuration(site_config_libdir, SiteConfigLibdir) :- ... /* Where user's arch-specific libraries are found by default. */ xsb_configuration(user_config_libdir, UserConfigLibdir) :- ...
| ?- xsb_flag(FlagName, Value), fail. |
The flag names currently supported are:
Flag Name | Purpose |
debugging | "on" iff debug mode is on; "off" otherwise. |
tracing | "on" iff trace mode is on; "off" otherwise. |
goal | the goal passed to XSB on command line with the `-e' switch; `true.' if nothing is passed. |
dcg_style | the DCG style currently used; xsb or standard (standard is used in Quintus, SICSTUS, etc.). See Section 9.4 for more details. |
garbage_collection | "none", "sliding", or "copying" depending on the garbage collection strategy that is currently being employed (see also Section 3.5). |
Note that xsb_flag is used only for dynamic XSB settings, i.e., settings that might change between sessions or within the same session. For static configuration information, the predicate xsb_configuration/2 is used.
| ?- hilog_symbol(X). |
xfx xfy yfx fx fy hx hy xf yf
Exceptions (not yet implemented):