The library(option) provides some utilities for processing option lists. Option lists are commonly used as an alternative for many arguments. Examples built-in predicates are open/4 and write_term/3. Naming the arguments results in more readable code and the list nature makes it easy to extend the list of options accepted by a predicate. Option lists come in two styles, both of which are handled by this library.
Processing options inside time critical code (loops) can cause serious overhead. One possibility is to define a record using library(record) and initialise this using make_<record>/2. In addition to providing good performance, this also provides type-checking and central declaration of defaults.
:- record atts(width:integer=100, shape:oneof([box,circle])=box).
process(Data, Options) :-
make_atts(Options, Attributes),
action(Data, Attributes).
action(Data, Attributes) :-
atts_shape(Attributes, Shape),
...
| Option | Term of the form Name(?Value). |
| Option | Term of the form Name(?Value). |
meta_options(is_meta, OptionsIn, Options),
...
is_meta(callback).