APL Wiki logo: Difference between revisions
Jump to navigation
Jump to search
Miraheze>Adám Brudzewsky (WIP) |
Miraheze>Adám Brudzewsky |
||
Line 52: | Line 52: | ||
1 | 1 | ||
</source> | </source> | ||
A really nice feature of APL is its array-orientation. For computations which are defined on single elements, [[wikipedia:map (higher-order function)|map]]ping is implicit: | |||
<source lang=apl> | <source lang=apl> | ||
0 1 2 3 4!4 | |||
1 4 6 4 1 | |||
</source> | </source> | ||
(What's up with picking zero out of four items? Since all empty hands are equal, there is exactly one such set — the empty set.) | |||
== Order of evaluation == | |||
We want to generate the indices using <source lang=apl inline>⍳</source>… | |||
<source lang=apl> ⍳5!4 | |||
| |||
</source> | |||
That didn't work! This is because APL dispenses with traditional mathematics' confusing and inconsistent precedence order<ref>K.E. Iverson, [https://www.jsoftware.com/papers/EvalOrder.htm Conventions Governing Order of Evaluation] (Appendix A of Elementary Functions: An Algorithmic Treatment). Science Research Associates, 1966</ref>, replacing it with a simple right-to-left rule: | |||
<source lang=apl> | |||
(⍳5)!4 | |||
1 4 6 4 1 | |||
</source> | |||
== Swapping arguments == | |||
If the arguments of <source lang=apl inline>!</source> were swapped, we didn't need that parenthesis. Enter the [[operator]] (higher-order function) [[swap]] (<source lang=apl inline>⍨</source>) which takes a [[dyadic]] function on its left and creates a new [[derived function]] which is identical to the original, but has swapped arguments: | |||
<source lang=apl> | <source lang=apl> | ||
4!⍨⍳5 | |||
1 | 1 4 6 4 1 | ||
</source> | </source> | ||
== References == | == References == | ||
<references /> | <references /> |