Short-circuit evaluation: Difference between revisions
Content added Content deleted
(Logo) |
(→Icon and Unicon: comments) |
||
Line 118:
</pre>
== Icon and Unicon ==
The entire concept of using 'boolean' values for logic control runs counter to the philosophy of Icon.
While this task could be written literally, it would be more beneficial to show how an Icon programmer would approach the same problem. Icon already embraces the idea of short circuit evaluation and goes further with the ability of expressions to generate alternate results only if needed. For more information see [[Icon%2BUnicon/Intro#Program_Flow_and_Control|Failure is an option, Everything Returns a Value Except when it Doesn't, and Goal-Directed Evaluation and Generators]]. Consequently some small liberties will be taken with this task:
* For false we will use the null value &null and true we will use anything else (a 1 will do).
* Short-circuit evaluation uses success (a result) and failure (a signal that cannot be ignored and no result) so strictly speaking the boolean false will not be returned (only the failure signal).
|