[ Arithmetic | Reference Manual | Alphabetic Index ]

eval(+Expression, -Result)

Used to evaluate eval/1 terms in arithmetic expressions.
Expression
An arithmetic expression.
Result
Output: a number.

Description

This is one of the predicates used by the ECLiPSe compiler to expand arithmetic expressions. If an expression contains a subexpression that is not known at compile time, it must be wrapped in eval/1, e.g.
   X is eval(Expr)+1
This will be compiled into the sequence
   eval(Expr,T1), +(T1,1,X)
and eval/2 will interpret the expression Expr at runtime.

Modes and Determinism

Modules

This predicate is sensitive to its module context (tool predicate, see @/2).

Exceptions

(4) instantiation fault
Expression is uninstantiated.
(21) undefined arithmetic expression
An evaluation predicate in the expression is not defined.
(24) number expected
Expression is not a valid arithmetic expression.

Examples

   % Given the program code:
   p(Number, Result) :-     Result is Number + 1.
   q(Expression, Result) :- Result is eval(Expression) + 1.

   % Only q/1 accepts expressions:
   ?- p(2+3, R).
   number expected in +(2 + 3, 1, _177)
   Abort

   ?- q(2+3, R).
   R = 6
   Yes (0.00s cpu)

See Also

is / 2