2,962
edits
(Control structure system) |
(→Control structures: Link to Batenburg paper that proposed the control structure system) |
||
Line 22: | Line 22: | ||
== Control structures == | == Control structures == | ||
[[Control structure]]s | [[Control structure]]s in APL2C are written using the <syntaxhighlight lang=apl inline>∇</syntaxhighlight> character, which is not used for [[defined function|function definition]] because this is initiated with editor interaction rather than source code. All control structures consist of an opening <syntaxhighlight lang=apl inline>∇</syntaxhighlight> followed by an expression, and closed with <syntaxhighlight lang=apl inline>∇</syntaxhighlight> alone. For example, the following structure doubles <syntaxhighlight lang=apl inline>X</syntaxhighlight> if it's less than 3. | ||
<syntaxhighlight lang=apl> | <syntaxhighlight lang=apl> | ||
∇X<3 | ∇X<3 | ||
Line 28: | Line 28: | ||
∇ | ∇ | ||
</syntaxhighlight> | </syntaxhighlight> | ||
If the | The interpretation of the control expression's result follows a proposal of F.H.D. van Batenburg.<ref>F. H. D. van Batenburg. [https://dl.acm.org/doi/10.1145/114054.114092 L-one-two-three (L1:..L2:..L3:) considered harmful] at [[APL91]].</ref> If the result is a non-negative number, the enclosed code is repeated that many times. A negative number indicates to repeat a number of times equal to the absolute value, but return to the controlling expression afterwards, allowing "while" to be implemented. A vector indicates counts for multiple sections, which are each preceded with a label-less <syntaxhighlight lang=apl inline>:</syntaxhighlight>, allowing "if-else" and "select" forms. | ||
== References == | == References == | ||
<references/> | <references/> | ||
{{APL dialects}}[[Category:APL dialects]][[Category:Nested array languages]][[Category:Ahead-of-time compilers]] | {{APL dialects}}[[Category:APL dialects]][[Category:Nested array languages]][[Category:Ahead-of-time compilers]] |