1:- module(
    2  default,
    3  [
    4    call_default_value/2,  % ?Value, :Goal_1
    5    call_default_value/3,  % ?Value, :Goal_1, +DefaultValue
    6    default_value/2,       % ?Value, +DefaultValue
    7    default_value/3        % ?FromValue, -ToValue, +DefaultValue
    8  ]

Support for default values


   15:- meta_predicate
   16    call_default_value(?, 1),
   17    call_default_value(?, 1, +).
 call_default_value(?Value, :Goal_1) is det
If `Value' is not bound, call `Goal_1' to determine its default value.
   28call_default_value(Value, _) :-
   29  nonvar(Value), !.
   30call_default_value(Value, Goal_1) :-
   31  call(Goal_1, Value).
 call_default_value(?Value, :Goal_1, +DefaultValue) is det
If `Value' cannot be determined by calling `Goal_1', the `DefaultValue' is used instead.
   39call_default_value(Value, Goal_1, _) :-
   40  call(Goal_1, Value), !.
   41call_default_value(DefaultValue, _, DefaultValue).
 default_value(?Value, +DefaultValue) is det
Returns either the given value or the default value, in case there is no value given.


Ordering is a meta-argument that allows a list of elements to be arbitrarily ordered. The use of default_value/2 here allows the original ordering of elements to be retained in case the Ordering argument is not instantiated.

default_value(=, Ordering),
once(call(Ordering, L1, L2))
   62default_value(Value, _):-
   63  nonvar(Value), !.
   64default_value(DefaultValue, DefaultValue).
 default_value(?FromValue, -ToValue, +DefaultValue) is det
Returns the given value, unless the given value is a variable. In the latter case, the default value is returned instead.

@note We are sometimes using this predicate instead of default_value/2 from `library(default)' because we do not want variable occurrences of `FromValue' to get instantiated.

   77default_value(X, Y, Y):-
   78  var(X), !.
   79default_value(X, X, _)