Direct function: Difference between revisions

Content deleted Content added
m Task 70: Update syntaxhighlight tags - remove use of deprecated <source> tags
m convert special characters (via WP:JWB)
Line 96:
{{quote|Complex numbers can be constructed as ordered pairs of real numbers, similar to how integers can be constructed as ordered pairs of natural numbers and rational numbers as ordered pairs of integers. For complex numbers, {{code|{⍺+0j1×⍵}|apl}} plays the same role as {{code|-|apl}} for integers and {{code|÷|apl}} for rational numbers.<ref name=Hui2016/>{{rp|§8}}}}
 
Moreover, analogous to that monadic {{code|-⍵|apl}} &hArr; {{code|0-⍵|apl}} (''negate'') and monadic {{code|÷⍵|apl}} &hArr; {{code|1÷⍵|apl}} (''reciprocal''), a monadic definition of the function is useful, effected by specifying a default value of 0 for {{code|⍺|apl}}: if {{code|j←{⍺←0 ⋄ ⍺+0j1×⍵}|apl}}, then {{code|j ⍵|apl}} &hArr; {{code|0 j ⍵|apl}} &hArr; {{code|0+0j1×⍵|apl}}.
 
<syntaxhighlight lang=apl>
Line 318:
</syntaxhighlight>
 
The algorithm works by sorting the rows individually ({{code|{⍵[⍋⍵]}⍤1 ⊢a|apl}}), and these sorted rows are used as keys ("signature" in the Programming Pearls description) to the ''key'' operator {{code|⌸|apl}} to group the rows of the matrix.<ref name=APL1978/>{{rp|§3.3}} The expression on the right is a ''train'', a syntactic form employed by APL to achieve [[tacit programming]]. Here, it is an isolated sequence of three functions such that {{code|(f g h) ⍵|apl}} &hArr; {{code|(f ⍵) g (h ⍵)|apl}}, whence the expression on the right is equivalent to {{code|({⍵[⍋⍵]}⍤1 ⊢a) {⊂⍵}⌸ a|apl}}.
 
=== Lexical scope ===