_lazy_and,
_lazy_or
-- ``lazy evaluation'' of Boolean expressions_lazy_and(b1, b2...)
evaluates the Boolean expression
b1 and b2 and ...
by ``lazy evaluation''.
_lazy_or(b1, b2...)
evaluates the Boolean expression
b1 or b2 or ...
by ``lazy evaluation''.
_lazy_and(b1, b2...)
_lazy_or(b1, b2...)
b1, b2, ... |
- | Boolean expressions |
TRUE
, FALSE
, or UNKNOWN
.
b1
, b2
, ...
and
, bool
, if
, is
, or
, repeat
, while
, FALSE
, TRUE
, UNKNOWN
_lazy_and(b1, b2...)
produces the same result as
bool(b1 and b2 and ...)
, provided the latter call does not
produce an error. The difference between these calls is as follows:
bool(b1 and b2 and ...)
evaluates all Boolean
expressions before combining them logically via 'and'.
Note that the result is FALSE
if one of b1
,
b2
etc. evaluates to FALSE
. ``Lazy evaluation'' is based on
this fact: _lazy_and(b1, b2...)
evaluates the arguments
from left to right. The evaluation is stopped immediately if one
argument evaluates to FALSE
. In this case,
_lazy_and
returns FALSE
without
evaluating the remaining Boolean expressions. If none of the
expressions b1
, b2
etc. evaluates to FALSE
, then all arguments are
evaluated and the corresponding result TRUE
or UNKNOWN
is returned.
_lazy_and
is also called ``conditional
and
''.
_lazy_or(b1, b2...)
produces the same result as
bool(b1 or b2 or ...)
, provided the latter call does not
produce an error. The difference between these calls is as follows:
bool(b1 or b2 or ...)
evaluates all Boolean
expressions before combining them logically via 'or'.
Note that the result is TRUE
if one of b1
,
b2
etc. evaluates to TRUE
. ``Lazy evaluation'' is based on
this fact: _lazy_or(b1, b2...)
evaluates the arguments
from left to right. The evaluation is stopped immediately if one
argument evaluates to TRUE
. In this case,
_lazy_or
returns TRUE
without
evaluating the remaining Boolean expressions. If none of the
expressions b1
, b2
etc. evaluates to TRUE
, then all arguments are
evaluated and the corresponding result FALSE
or UNKNOWN
is returned.
_lazy_or
is also called ``conditional
or
''.
b1
,
b2
etc. cannot be evaluated to TRUE
, FALSE
, or UNKNOWN
, then
_lazy_and
, _lazy_or
produce errors._lazy_and
and _lazy_or
are internally
used by the if
, repeat
, and
while
statements. For example, the statement 'if b1
and b2 then ...
' is equivalent to 'if _lazy_and(b1, b2)
then ...
'._lazy_and()
returns TRUE
._lazy_or()
returns FALSE
._lazy_and
is a function of the system kernel._lazy_or
is a function of the system kernel.This example demonstrates the difference between lazy evaluation and complete evaluation of Boolean conditions. For x = 0, the evaluation of sin(1/x) leads to an error:
>> x := 0: bool(x <> 0 and sin(1/x) = 0)
Error: Division by zero
With ``lazy evaluation'', the expression sin(1/x) = 0 is not evaluated. This avoids the previous error:
>> _lazy_and(x <> 0, sin(1/x) = 0)
FALSE
>> bool(x = 0 or sin(1/x) = 0)
Error: Division by zero
>> _lazy_or(x = 0, sin(1/x) = 0)
TRUE
>> delete x:
The following statements do no produce an error, because
if
uses lazy evaluation
internally:
>> for x in [0, PI, 1/PI] do if x = 0 or sin(1/x) = 0 then print(x) end_if; end_for:
0 1 -- PI
>> delete x:
Both functions can be called without parameters:
>> _lazy_and(), _lazy_or()
TRUE, FALSE