built-in predicate
logtalk_load_context/2
¶
Description¶
logtalk_load_context(Key, Value)
Provides access to the Logtalk compilation/loading context. The following keys are currently supported:
entity_identifier
- identifier of the entity being compiled if anyentity_prefix
- internal prefix for the entity compiled codeentity_type
- returns the valuemodule
when compiling a module as an objectsource
- full path of the source file being compiledfile
- the actual file being compiled, different fromsource
only when processing aninclude/1
directivebasename
- source file basenamedirectory
- source file directorystream
- input stream being used to read source file termstarget
- the full path of the intermediate Prolog fileflags
- the list of the explicit flags used for the compilation of the source fileterm
- the source file term being compiledterm_position
- the position of the term being compiled (StartLine-EndLine
)variables
- the variables of the term being compiled ([Variable1, ...]
)variable_names
- the variable names of the term being compiled ([Name1=Variable1, ...]
)singletons
- the singleton variables of the term being compiled ([Name1=Variable1, ...]
)
This predicate is usually called by the term_expansion/2
and goal_expansion/2 methods. It can also be called directly
from initialization/1 directives in a source file. Note
that the entity keys are only available when compiling an entity term or
from an object initialization/1
directive.
Warning
The term_position
key is only supported in
backend Prolog compilers
that provide access to the start and end lines of a read term. When
such support is not available, the value -1
is returned for both
the start and the end lines.
Currently, any variables in the values of the term
, variables
,
variable_names
, and singletons
keys are not shared with,
respectively, the term and goal arguments of the term_expansion/2
and goal_expansion/2
methods.
Using the variables
, variable_names
, and singletons
keys
may require calling the standard built-in predicate term_variables/2
on the term read and unifying the term variables with the variables
in the names list. This, however, may rise portability issues with
Prolog compilers that don’t return the variables in the same order for
the term_variables/2
predicate and the option variable_names/1
of the read_term/3
built-in predicate, which is used by the Logtalk
compiler to read source files.
Modes and number of proofs¶
logtalk_load_context(?atom, -nonvar) - zero_or_more
Errors¶
(none)
Examples¶
% expand source file terms only if they are entity terms
term_expansion(Term, ExpandedTerms) :-
logtalk_load_context(entity_identifier, _),
....
% define a library alias based on the source directory
:- initialization((
logtalk_load_context(directory, Directory),
assertz(logtalk_library_path(my_app, Directory))
)).
See also