Did you know ... | Search Documentation: |
![]() | Pack canny_tudor -- prolog/swi/options.pl |
Defaults are unbound if not present. The implementation selects an
option's Default from the given list of Defaults using
select_option/4. Option terms must have one variable. This is
because select_option/4's fourth argument is a single argument. It
never unifies with multiple variables even though it succeeds, e.g.
select_option(a(A, B), [], Rest, 1)
unifies A with 1, leaving B
unbound.
There is a naming issue. What to call the incoming list of Option arguments and the Options argument with which the Option terms unify? One possibility: name the Options argument RestOptions0 since they represent the initial set of RestOptions from which Options select. This clashes with select_option/4's naming convention since Options is the argument name for RestOptions0's role in the option-selection process. Nevertheless, this version follows this renamed argument convention.
The predicate is useful for selecting options from a list of options, especially when the options are not known in advance or when they need to be filtered based on certain criteria.
Example:
?- select_options([a(A), b(B)], [a(1), b(2), c(3)], Rest, [a(0), b(0)]). Rest = [c(3)], A = 1, B = 2.