2,951
edits
m (Text replacement - "Category:Primitive functions" to "Category:Primitive functionsCategory:Functions with first- and last-axis forms") |
|||
(6 intermediate revisions by 2 users not shown) | |||
Line 37: | Line 37: | ||
0 2 ¯3 1 / ⍳4 | 0 2 ¯3 1 / ⍳4 | ||
2 2 0 0 0 4 | 2 2 0 0 0 4 | ||
</source>{{Works in|[[NARS2000]], [[Dyalog APL]], [[APLX]], [[ngn/ | </source>{{Works in|[[NARS2000]], [[Dyalog APL]], [[APLX]], [[ngn/apl]]}} | ||
<source lang=apl> | <source lang=apl> | ||
0 2 ¯3 1 / ⍳3 | 0 2 ¯3 1 / ⍳3 | ||
Line 46: | Line 46: | ||
1 ¯2 3 / 'a' | 1 ¯2 3 / 'a' | ||
a aaa | a aaa | ||
</source>{{Works in|[[NARS2000]], [[APL2]], [[Dyalog APL]], [[APLX]], [[ngn/ | </source>{{Works in|[[NARS2000]], [[APL2]], [[Dyalog APL]], [[APLX]], [[ngn/apl]], [[GNU APL]]}} | ||
=== High-rank arrays === | === High-rank arrays === | ||
Replicate works along a particular [[axis]], which can be specified in languages with [[function axis]] and otherwise is the first axis for <source lang=apl inline>⌿</source>, and the last axis for <source lang=apl inline>/</source> (except in [[A+]], which uses <source lang=apl inline>/</source> for the [[Leading axis theory|first-axis]] form and has no last-axis form | Replicate works along a particular [[axis]], which can be specified in languages with [[function axis]] and otherwise is the first axis for <source lang=apl inline>⌿</source>, and the last axis for <source lang=apl inline>/</source> (except in [[A+]], which uses <source lang=apl inline>/</source> for the [[Leading axis theory|first-axis]] form and has no last-axis form). | ||
<source lang=apl> | <source lang=apl> | ||
⊢A ← 4 6⍴⎕A | ⊢A ← 4 6⍴⎕A | ||
Line 73: | Line 73: | ||
b bbb | b bbb | ||
c ccc | c ccc | ||
</source>{{Works in|[[APL2]], [[Dyalog APL]], [[APLX]], [[ngn/APL]], [[GNU APL]]}} | </source>{{Works in|[[APL2]], [[Dyalog APL]], [[APLX]], [[ngn/apl]], [[GNU APL]]}} | ||
[[dzaima/APL]] expects arguments of <source lang=apl inline>⌿</source> to have matching shape, and replicates the [[ravel]] of both. | |||
=== Operator or function? === | |||
The syntax <source lang=apl inline>a / b</source> is ambiguous: it may be an invocation of a [[dyadic function]] <source lang=apl inline>/</source> with left [[argument]] <source lang=apl inline>a</source> and right argument <source lang=apl inline>b</source>, or of a [[monadic operator]] with [[operand]] <source lang=apl inline>a</source> and right argument <source lang=apl inline>b</source>. In early APLs there was no way to resolve this ambiguity, but with the extension of [[operator]]s to allow arbitrary function operands instead of a specified set of [[primitive function]]s, the distinction becomes apparent: a function Replicate can be used as an [[operand]] while an operator Replicate cannot. | |||
One test of Replicate's nature is to try Replicate [[Each]]<ref>Benkard, J. Philip. [https://dl.acm.org/doi/10.1145/384282.28345 "Replicate each, anyone?"]. [[APL87]].</ref> with an expression such as <source lang=apl inline>1 3 /¨ 'ab' 'cd'</source>. If Replicate is implemented as an operator, it will be applied to the operand <source lang=apl inline>1 3</source>, and Each will be applied to the resulting [[derived function]] <source lang=apl inline>1 3/</source>. | |||
<source lang=apl> | |||
1 3 /¨ 'ab' 'cd' | |||
abbb cddd | |||
(1 3/)¨ 'ab' 'cd' | |||
abbb cddd | |||
</source>{{Works in|[[SHARP APL]] (with <source lang=apl inline>¨></source> in place of <source lang=apl inline>¨</source>), [[APL2]], [[APLX]]}} | |||
If Replicate is a function, then Each will apply to Replicate only, and the resulting derived function will be invoked monadically. | |||
<source lang=apl> | |||
1 3 /¨ 'ab' 'cd' | |||
ab cccddd | |||
1 3 (/¨) 'ab' 'cd' | |||
ab cccddd | |||
</source>{{Works in|[[NARS2000]], [[Dyalog APL]], [[GNU APL]]}} | |||
In early APLs such as [[APL\360]], applying an operator to Compress will always result in a [[SYNTAX ERROR]], because Compress is not an allowed operand of any operator. This is also the case in [[ngn/apl]]: although operators can apply to any function, Replicate cannot be used unless both arguments are immediately available. In both cases there is no way to determine whether Replicate "acts like a function" or "acts like an operator". | |||
== History == | == History == | ||
Line 121: | Line 143: | ||
| [[GNU APL]] || Function || {{Yes}} || {{No}} || {{Yes}} || {{Yes|APL2}} || {{Yes}} || | | [[GNU APL]] || Function || {{Yes}} || {{No}} || {{Yes}} || {{Yes|APL2}} || {{Yes}} || | ||
|- | |- | ||
| [[dzaima/APL]] (<source lang=apl inline>⌿</source>) || Function || {{Yes}} || {{Yes}} || {{No}} || {{None}} || {{No}} || | | [[dzaima/APL]] (<source lang=apl inline>⌿</source>) || Function || {{Yes}} || {{Yes}} || {{No}} || {{None}} || {{No}} || | ||
|} | |} | ||
Line 153: | Line 175: | ||
<references /> | <references /> | ||
{{APL built-ins}} | {{APL built-ins}}[[Category:Primitive functions]][[Category:Functions with first- and last-axis forms]] |