Next: Numeric Types and Type
Up: Arithmetic
Previous: Arithmetic
  Index
Built-Ins to Evaluate Arithmetic Expressions
Unlike other languages, Prolog usually interprets an arithmetic expression like
3 + 4 as a compound term with functor + and two arguments.
Therefore a query like 3 + 4 = 7 fails because a compound term does not
unify with a number. The evaluation of an arithmetic expression has to be
explicitly requested by using one of the built-ins described below.
The basic predicate for evaluating an arithmetic expression is is/2.
Apart from that only the 6 arithmetic comparison predicates evaluate
arithmetic expressions automatically.
- Result is Expression
-
Expression is a valid arithmetic expression and Result
is an uninstantiated variable or a number.
The system evaluates Expression which yields a numeric result.
This result is then unified with Result.
An error occurs if Expression is not a valid arithmetic expression or
if the evaluated value and Result are of different types.
- Expr1 < Expr2
-
succeeds if (after evaluation and type coercion) Expr1 is less than Expr2.
- Expr1 >= Expr2
-
succeeds if (after evaluation and type coercion) Expr1 is greater or equal to Expr2.
- Expr1 > Expr2
-
succeeds if (after evaluation and type coercion) Expr1 is greater than Expr2.
- Expr1 =< Expr2
-
succeeds if (after evaluation and type coercion) Expr1 is less or equal to Expr2.
- Expr1 =:= Expr2
-
succeeds if (after evaluation and type coercion) Expr1 is equal to Expr2.
- Expr1
=\=
Expr2
-
succeeds if (after evaluation and type coercion) Expr1 is not equal to Expr2.
Next: Numeric Types and Type
Up: Arithmetic
Previous: Arithmetic
  Index
1999-08-06