next up previous contents index
Next: List Manipulation Up: Built-in predicates Previous: Arithmetic Functions   Contents   Index

Adding Arithmetic Functions

Prolog predicates can be given the role of arithmetic function. The last argument is used to return the result, the arguments before the last are the inputs. Arithmetic functions are added using the predicate arithmetic_function1, which takes the head as its argument. Arithmetic functions are module sensitive, that is they are only visible from the module in which the function is defined and declared. Global arithmetic functions should be defined and registered from module user. Global definitions can be overruled locally in modules. The builtin functions described above can be redefined as well.

arithmetic_function1+Head Register a Prolog predicate as an arithmetic function (see is2, 2, etc.). The Prolog predicate should have one more argument than specified by Head, which it either a term Name/Arity, an atom or a complex term. This last argument is an unbound variable at call time and should be instantiated to an integer or floating point number. The other arguments are the parameters. This predicate is module sensitive and will declare the arithmetic function only for the context module, unless declared from module user. Example:


\begin{code}
1 ?- [user].
:- arithmetic_function(mean/2).
\par mean(A, B, C) :-
...
...0.07 sec, 440 bytes.
\par Yes
2 ?- A is mean(4, 5).
\par A = 4.500000
\end{code}

current_arithmetic_function1?Head Successively unifies all arithmetic functions that are visible from the context module with Head.


next up previous contents index
Next: List Manipulation Up: Built-in predicates Previous: Arithmetic Functions   Contents   Index
Dr. Richard Botting 2001-12-12