|Page 183 of 800||Search internet|
Most of the constructs presented so far compute their arguments left to right and inspect each resulting value for being an exception. If an argument evaluates into an exception, the remaining arguments are not evaluated, and the exception becomes the value of the expression. Some examples read:
The examples above show that the plus operation 'relays' exceptions in the sense that if an argument evaluates to an exception, that exception is 'relayed' to become the return value. When more than one argument evaluates to an exception, the leftmost exception is relayed.
The following examples show the evaluation order more explicitly:
Computation of takes infinite time. In the first case above, is evaluated yielding an exception which is relayed without the second argument being evaluated. In the second case above, is evaluated which takes forever.
Most of the constructs presented so far are 'eager left-relaying' in the following sense:
They are eager in the sense that they evaluate all their arguments unless argument evaluation is aborted by an exception.
They are relaying in the sense that if an argument returns an exception, that exception becomes the result of the operation.
They are left-to-right in the sense that arguments are evaluated left to right.
The comments above should be taken with a grain of salt since an implementation is free to do computation in any order as long as the return value of each operation is as specified. As an example, consider this:
Evaluation of the sum above will force both print statements to be evaluated. On some implementations, evaluation of a print statement has the side effect that the argument of the print statement is printed to the users terminal. On such implementations, one will typically see the A before the B because, typically, implementations actually do compute arguments left-to-right. But nothing prevents an implementation to do 'speculative parallelism' in which it computes both arguments in parallel and aborts the second computation if the first one raises an exception.
Three constructs presented so far in the present Programming language chapter are not eager left-relaying. They are:
All three fail to be eager in that for some non-exceptional values of x they do not evaluate y.
Note that itself is relaying. As an example, we have:
On the left hand side above, the first raise construct raises an exception which the second raise construct relays.
The Logiweb programming language itself is a lazy language. It is just the constructs presented so far which are eager.
Furthermore, to Logiweb, exceptions are data structures like any other data structures. It is just the constructs presented so far which treat exceptions specially. As an example, it is possible to forge a pair whose first component is and whose second component is . But it is not possible to use to forge such a pair since the relays the exception. That, however, is due to the behavior of the construct. Logiweb itself has no reservations against exceptions as components of pairs.
|Page 183 of 800||Search logiweb.eu|