Language Reference/Terms/Arguments

This section describes named, default, optional parameters and functor originals. Even though these notions are individual they also have a significant impact on each other and therefore they are described together.

In brief:


 * Named parameters: In a call the actual arguments can be supplied by formal parameter name rather than position.
 * Default parameters: A default parameter value can be stated together with a formal argument in a predicate declaration. This value is used when no actual parameter is supplied.
 * Optional parameters: An actual parameter is optional and can therefore be skipped.
 * Functor originals: Functor term which is used as/bound to the original of another functor term (in a functor term expression).

Named parameters
The formal parameter names from a declaration can be used to specify the actual arguments in a call by using the syntax : = .

Default parameters
A default parameter is defined by adding =  after a formal input parameter in a declaration (  must be a compile time constant expression).

Notice that it is illegal to provide default parameters for [out] parameters.

Optional parameters
If a parameter is [out] or if it has a default value, then the actual argument is optional and can be skipped provided that it is the last argument in the call. Skipping an [out] parameter corresponds to supplying an anonymous variable for that parameter. Skipping a parameter that has a default value corresponds to supplying the default value for the parameter.

An optional out parameter can cause conflict with another predicate:

The attribute [mandatoryOut] can be used to avoid such conflicts and/or if it doesn't seem appropriate that a predicate a has optional output parameters.

Functor originals
A functor original is a syntactic construction that describes an original for a functor term expression. Syntactically it takes the following form:

( | )

The functor original can either be a a functor value or a free variable. In both cases the construction indicates that the functor may have more arguments than those mentioned explicitly in front of the bar.

If the functor original is a functor value then it will be used as original for constructing a new functor value.

The functor original can be any kind of term as long as it evaluates to an appropriate functor term.

If a functor domain has more than one alternative, then the functor original must be of same kind as the term that is constructed.

In a functor match the functor original can be an anonymous variable. And in that it simply indicates that the term can have more components which we don't care about.

In a functor match the functor original can be a named variable. If the variable is bound then it is used as an original for constructing a functor value and then that functor value is used in the match.

If the functor original is a free variable (in a functor match) then that variable will be bound to the entire functor term: