Replicate: Difference between revisions

Jump to navigation Jump to search
115 bytes added ,  10:09, 4 May 2020
m
(Operator vs. function test)
(5 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/APL]]}}
</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/APL]], [[GNU APL]]}}
</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, and [[dzaima/APL]], which is similar but uses <source lang=apl inline>⌿</source>).
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? ===
=== Operator or function? ===
Line 82: Line 84:
<source lang=apl>
<source lang=apl>
       1 3 /¨ 'ab' 'cd'   
       1 3 /¨ 'ab' 'cd'   
abbb  cddd
abbb  cddd
       (1 3/)¨ 'ab' 'cd'
       (1 3/)¨ 'ab' 'cd'
abbb  cddd
abbb  cddd
</source>{{Works in|[[SHARP APL]] (with <source lang=apl inline>¨></source> in place of <source lang=apl inline>¨</source>), [[APL2]], [[APLX]]}}
</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.
If Replicate is a function, then Each will apply to Replicate only, and the resulting derived function will be invoked monadically.
<source lang=apl>
<source lang=apl>
       1 3 /¨ 'ab' 'cd'   
       1 3 /¨ 'ab' 'cd'   
ab  cccddd
ab  cccddd
       1 3 (/¨) 'ab' 'cd'
       1 3 (/¨) 'ab' 'cd'
ab  cccddd
ab  cccddd
</source>{{Works in|[[NARS2000]], [[Dyalog APL]], [[GNU APL]]}}
</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".
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 141: 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}}  || Vector right argument only
| [[dzaima/APL]] (<source lang=apl inline>⌿</source>) || Function  || {{Yes}} || {{Yes}} || {{No}}  || {{None}}            || {{No}}  ||
|}
|}


Line 173: Line 175:
<references />
<references />


{{APL built-ins}}
{{APL built-ins}}[[Category:Primitive functions]][[Category:Functions with first- and last-axis forms]]

Navigation menu