Did you know ... Search Documentation:
Pack arithmetic_types -- prolog/arithmetic_types.pl
PublicShow source

This module extends the existing library(arithmetic) to support expressions with atomic values and user defined types. Such types include compound terms which are not functions. A user defined type is typically packaged as a module with its associated function definitions. These predicates need not, and typically do not export the predicates; the exports of such modules are the set of globally visible functions they define. Functions can be "polymorphic" in that the same function Name/Arity can be defined for more than one type; in such cases they are distinguished by the argument types.

This module extends the functionality of library(arithmetic) and exports the same predicate set. Conflicts are largely avoided since arithmetic type expansion is done before library(arithmetic) expansion is invoked.

Functions are defined using the directive arithmetic_function/1. When this directive is encountered at load time, the predicate for that function must either be defined and visible to the module or will be defined subsequently in the module being loaded. This permits, for example, an imported predicate to be used as an function given the right argument pattern. Alternatively, it can be overloaded by defining a local predicate prior to using this directive to define the function.

Runtime evaluation is provided by arithmetic_expression_value/2.

 arithmetic_function(NameArity) is det
Declare a predicate as an arithmetic function.
 arithmetic_expression_value(:Expression, -Result) is det
True when Result unifies with the arithmetic result of evaluating Expression.