"Fossies" - the Fresh Open Source Software Archive

Member "gentle-97/html/dataflow.html" (20 Aug 1998, 2006 Bytes) of package /linux/misc/old/gentle-97.tar.gz:


Caution: In this restricted "Fossies" environment the current HTML page may not be correctly presentated and may have some non-functional links. You can here alternatively try to browse the pure source code or just view or download the uninterpreted raw source code. If the rendering is insufficient you may try to find and view the page on the gentle-97.tar.gz project site itself.



HANDBOOK / GENTLE PRIMER / Control Structures /

Dataflow

In our example, the variables A and B are defined outside the alternative statement. They can be used inside.

The general rule is: A variable that is used in a pattern must be in a defined state at the beginning of the whole alternative statement, or must defined by a preceding member of the same alternative.

In the example, the variable C is used after the alternative statement, and has no definition outside the alternative statement. This is allowed because it is defined in both alternatives. Regardless of which alternative is taken, C would be defined in all cases (if no alternative is applicable then statement using C will not be reached).

The general rule is: A variable that is defined in all alternatives is said to be defined by the whole alternative statement, and may be used subsequently. If a variable is defined in all alternatives, it must be defined everywhere with the same type.

If a variable is defined in one or more - but not all - alternatives, it is said to be local to the alternative containing the definition and cannot be used outside the alternative statement.

If, in the above example, we had written


   (| ge(A, B) process(A -> ResultA) || process(B -> ResultB) |)
neither ResultA nor ResultB could have been used in a subsequent statement because it could not be guaranteed that it is always defined.