4,500
edits
Line 4: | Line 4: | ||
== Examples == | == Examples == | ||
=== Basics === | |||
A simple [[dyadic function]]: | |||
<source lang=apl> | <source lang=apl> | ||
∇ r←l Tradfn r | ∇ r←l Tradfn r | ||
Line 11: | Line 12: | ||
∇ | ∇ | ||
</source> | </source> | ||
{{Works in|[[Dyalog APL]], [[APL2]], [[GNU APL]], [[NARS2000]]}} | {{Works in|[[Dyalog APL]], [[APL2]], [[GNU APL]], [[NARS2000]], [[APLX]], and every older APL from [[APL\360]]}} | ||
=== Braces === | |||
[[ | An [[ambivalent function]] with an optional left argument, a conditional [[control structure]], one local variable, and a [[shy]] result: | ||
<source lang=apl> | <source lang=apl> | ||
∇ | ∇ {res}←{left} AddMult2 right;local | ||
:If 0=⎕NC'left' ⍝ if variable "left" is not defined already | :If 0=⎕NC'left' ⍝ if variable "left" is not defined already | ||
left←0 | left←0 | ||
Line 22: | Line 23: | ||
res←2×local | res←2×local | ||
∇ | ∇ | ||
AddMult2 3 ⍝ result is "shy" | |||
⎕←AddMult2 3 ⍝ coerce display of result | |||
6 | |||
1 AddMult2 3 ⍝ result is "shy" | |||
10×1 AddMult2 3 ⍝ use result anyway | |||
80 | |||
</source> | </source> | ||
{{Works in|[[Dyalog APL]]}} | {{Works in|[[Dyalog APL]]}} | ||
=== Brackets === | |||
[[GNU APL]] allows functions and operators to accept an [[function axis|axis]] argument:<ref>[https://www.gnu.org/software/apl/apl.html#Section-3_002e2 3.2 Axis argument in defined functions] – GNU APL Manual</ref> | [[GNU APL]] allows functions and operators to accept an [[function axis|axis]] argument:<ref>[https://www.gnu.org/software/apl/apl.html#Section-3_002e2 3.2 Axis argument in defined functions] – GNU APL Manual</ref> | ||
<source lang=apl> | <source lang=apl> | ||
Line 36: | Line 43: | ||
</source> | </source> | ||
{{Works in|[[GNU APL]]}} | {{Works in|[[GNU APL]]}} | ||
=== Operators === | |||
A [[monadic operator]] and a [[dyadic operator]], both deriving [[monadic function]]s: | |||
<source lang=apl> | |||
∇ res←(Function SELF) right | |||
res←right Function right | |||
∇ | |||
×SELF 1 2 3 4 5 | |||
1 4 9 16 25 | |||
∇ res←(FunctionF HOOK FunctionG) right | |||
res←right FunctionF FunctionG right | |||
∇ | |||
÷HOOK|2 0 ¯7 | |||
1 1 ¯1 | |||
</source> | |||
{{Works in|[[Dyalog APL]], [[APL2]], [[GNU APL]], [[NARS2000]], [[APLX]]}} | |||
A monadic operator and a dyadic operator, both deriving [[dyadic function]]s: | |||
<source lang=apl> | |||
∇ res←left (Function SWAP) right | |||
res←right Function left | |||
∇ | |||
3 2 -SWAP 10 | |||
7 8 | |||
∇ res←left (FunctionF OVER FunctionG) right | |||
res←(FunctionG left) FunctionF (FunctionG right) | |||
∇ | |||
2 ¯7 2+OVER|¯3 1 4 | |||
5 8 6 | |||
</source> | |||
{{Works in|[[Dyalog APL]], [[APL2]], [[GNU APL]], [[NARS2000]], [[APLX]]}} | |||
== Representations == | == Representations == |