APL2C: Difference between revisions

Jump to navigation Jump to search
Control structure system
(Created page with "{{Infobox array language | logo = File:APL2C.gif | array model = nested | index origin = 0 or 1 | function styles = defined | numeric types = floats | unicode support = no | released = 2001 | developer = Tilman Otto | latest release version = 5.0.3 / 2002 | implementation languages = wikipedia:C_(programming_language...")
 
(Control structure system)
Line 19: Line 19:


APL2C's compiler generates [[wikipedia:C_(programming_language)|C]] code that calls functions for primitives and other operations such as loading variables, removing interpreter dispatch overhead. Compiling allows a program to be distributed as an executable file, and allows the APL code to inter-operate with C. It restricts some dynamic functionality: compiled programs can't dynamically create APL functions with <syntaxhighlight lang=apl inline>⎕FX</syntaxhighlight>, and can't pass arrays (rather than functions) as [[operand]]s to user-defined operators.
APL2C's compiler generates [[wikipedia:C_(programming_language)|C]] code that calls functions for primitives and other operations such as loading variables, removing interpreter dispatch overhead. Compiling allows a program to be distributed as an executable file, and allows the APL code to inter-operate with C. It restricts some dynamic functionality: compiled programs can't dynamically create APL functions with <syntaxhighlight lang=apl inline>⎕FX</syntaxhighlight>, and can't pass arrays (rather than functions) as [[operand]]s to user-defined operators.
== Control structures ==
[[Control structure]]s could be written using the <syntaxhighlight lang=apl inline>∇</syntaxhighlight> character, which was not used for [[defined function|function definition]] because this was initiated with editor interaction rather than source code. All control structures were written with 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>
∇X<3
X←2×X
</syntaxhighlight>
If the expression evaluates to 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 re-evaluate 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]]

Navigation menu