Defined function (traditional): Difference between revisions

Jump to navigation Jump to search
No edit summary
(One intermediate revision by one other user not shown)
Line 19: Line 19:
</source>
</source>
{{Works in|[[Dyalog APL]], [[APL2]], [[GNU APL]], [[NARS2000]], [[APLX]], and every older APL from [[APL\360]]}}
{{Works in|[[Dyalog APL]], [[APL2]], [[GNU APL]], [[NARS2000]], [[APLX]], and every older APL from [[APL\360]]}}
=== Semi-colons ===
Assignments are global by default. To keep a name local, it must be mentioned in the header, separated from the rest of the header by a semi-colon:
<source lang=apl>
      ∇ r←l Tradfn r;intermediate
        intermediate←l r
        r←intermediate intermediate
      ∇
</source>
{{Works in|[[Dyalog APL]], [[APL2]], [[GNU APL]], [[NARS2000]], [[APLX]], and every older APL from [[APL\360]]}}
=== Braces ===
=== Braces ===
An [[ambivalent function]] with an optional left argument, a conditional [[control structure]], one local variable, and a [[#Shyness|shy]] result:
An [[ambivalent function]] with an optional left argument, a conditional [[control structure]], one local variable, and a [[#Shyness|shy]] result:
Line 144: Line 154:


==== Shyness ====
==== Shyness ====
A tradfn can be declared as shy, that is, it exhibits the same behaviour as an assignment, in that by default, no result is printed when the function terminates, but attempting to use the result still succeeds. This declaration is done by putting curly braces around the result name (for example <source lang=apl inline>{result}←left Function right</source>).
By default, functions in APL will print their result to the session log even without using <source lang=apl inline>⎕←</source> unless their results are shy. Shy results are declared by putting curly braces around the result name (for example <source lang=apl inline>{result}←left Function right</source>). Assignment (<source lang=apl inline>name←array</source>) exhibits the same behaviour as a shy function in that, by default, no result is printed when the function terminates, but attempting to use the result still succeeds.


==== Namelists ====
==== Namelists ====

Navigation menu