Previous Page Next Page Contents

_lazy_and, _lazy_or -- ``lazy evaluation'' of Boolean expressions

Introduction

_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''.

Call(s)

_lazy_and(b1, b2...)
_lazy_or(b1, b2...)

Parameters

b1, b2, ... - Boolean expressions

Returns

TRUE, FALSE, or UNKNOWN.

Overloadable:

b1, b2, ...

Related Functions

and, bool, if, is, or, repeat, while, FALSE, TRUE, UNKNOWN

Details

Example 1

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:

Example 2

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:

Example 3

Both functions can be called without parameters:

>> _lazy_and(), _lazy_or()
                                TRUE, FALSE

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000