This library allows management of configuration settings for Prolog applications. Applications define settings in one or multiple files using the directive setting/4 as illustrated below:
:- use_module(library(settings)). :- setting(version, atom, '1.0', 'Current version'). :- setting(timeout, number, 20, 'Timeout in seconds').
The directive is subject to term_expansion/2, which guarantees proper synchronisation of the database if source-files are reloaded. This implies it is not possible to call setting/4 as a predicate.
Settings are local to a module. This implies they are defined in a two-level namespace. Managing settings per module greatly simplifies assembling large applications from multiple modules that configuration through settings. This settings management library ensures proper access, loading and saving of settings.
If a second declaration for a setting is encountered, it is ignored if Type and Default are the same. Otherwise a permission_error is raised.
setting(Name, Value)
only enumerates the settings of the
current module. All settings can be enumerated using
setting(Module:Name, Value)
. This predicate is det
if Name is
ground.
env(Name)
, but uses the value Default if the variable
is not defined.env(Var)
evaluates to the value of an environment variable.
If Type is atom
, concatenate A+B+.... Elements of the
expression can be env(Name)
.integer
, float
or
number
.settings(changed(Module:Name, Old, New))
Note that modified settings are not automatically persistent. The application should call save_settings/0 to persist the changes.
error
, an error is printed and the setting is ignored.
when load
, the setting is loaded anyway, waiting for a
definition.
If possibly changed settings need to be persistent, the application
must call save_settings/0 as part of its shutdown. In simple cases
calling at_halt(save_settings)
is sufficient.
current_output
. The second form only lists
settings on the matching module.
The following predicates are exported, but not or incorrectly documented.