APL Wiki logo: Difference between revisions

Jump to navigation Jump to search
976 bytes added ,  01:14, 3 November 2019
Miraheze>Adám Brudzewsky
(WIP)
 
Miraheze>Adám Brudzewsky
Line 52: Line 52:
1
1
</source>
</source>
And how about sets of five? Well, we only have for items, so there are no such sets:
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>
       5!4
       0 1 2 3 4!4
0
1 4 6 4 1
</source>
</source>
And how about picking out zero items? Since all empty hands are equal, there is exactly one such set — the empty set:
(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>
       0!4
       4!⍨⍳5
1
1 4 6 4 1
</source>
</source>
This shows another tendency in APL; that to generalise common operations even to edge cases.
 
Now we can ask
== References ==
== References ==
<references />
<references />

Navigation menu