|Did you know ...||Search Documentation:|
|Reflective access to options|
From the above, we conclude that we require reflective access to find
out whether an option is supported and valid for a particular predicate.
Possible option values must be described by types. Due to lack of a type
system, we use
library(error) to describe allowed option
values. Predicate options are declared using predicate_options/3:
Below is an example that processes the option
and passes all options to open/4:
:- predicate_options(write_xml_file/3, 3, [ header(boolean), pass_to(open/4, 4) ]). write_xml_file(File, XMLTerm, Options) :- open(File, write, Out, Options), ( option(header(true), Options, true) -> write_xml_header(Out) ; true ), ...
This predicate may only be used as a directive and is processed by expand_term/2. Option processing can be specified at runtime using assert_predicate_options/3, which is intended to support program analysis.
false, the predicate becomes semidet and fails without modifications if modifications are required.
The predicates below realise the support for compile and runtime checking for supported options.
?- current_predicate_option(open/4, 4, type(text)). true.
existence_error(option, OptionName)if the option is not supported by PI.
type_error(Type, Value)if the option is supported but the value does not match the option type. See must_be/2.
The predicates below can be used in a development environment to inform the user about supported options. PceEmacs uses this for colouring option names and values.
The library can execute a complete check of your program using check_predicate_options/0:
The library offers predicates that may be used to create declarations for your application. These predicates are designed to cooperate with the module system.
library(option)or passes options to other predicates that are known to process options. The process is repeated until no new declarations are retrieved.