4,493
edits
m (Categories) |
|||
(2 intermediate revisions by the same user not shown) | |||
Line 42: | Line 42: | ||
1 2 3 4 * 2 | 1 2 3 4 * 2 | ||
1 4 9 16 | 1 4 9 16 | ||
100,¨1 2 3 4 | |||
┌─────┬─────┬─────┬─────┐ | |||
│100 1│100 2│100 3│100 4│ | |||
└─────┴─────┴─────┴─────┘ | |||
</source> | </source> | ||
[[Replicate]] and [[ | [[Replicate]] and [[Partitioned Enclose]] (and also [[Partition]], but this is less useful, as it is equivalent to <source lang=apl inline>,⊂</source> or <source lang=apl inline>{0⍴⊂0⍴⍵}</source>) extend a scalar left argument to apply to each column of the right argument: | ||
<source lang=apl> | <source lang=apl> | ||
2/'abc' | 2/'abc' | ||
aabbcc | aabbcc | ||
2⊂'abc' | |||
┌┬─┬┬─┬┬─┐ | |||
││a││b││c│ | |||
└┴─┴┴─┴┴─┘ | |||
</source> | </source> | ||
[[Decode]] uses extends a single radix left argument to apply to all digit values in the right argument: | |||
<source lang=apl> | |||
2⊥1 0 1 | |||
5 | |||
</source> | |||
[[APL2]] and [[Dyalog APL]] use a variant of singleton extension when the selected axis of the right argument has length one: each element along that axis is reused for every element of the left argument. | [[APL2]] and [[Dyalog APL]] use a variant of singleton extension when the selected axis of the right argument has length one: each element along that axis is reused for every element of the left argument. | ||
<source lang=apl> | <source lang=apl> | ||
Line 65: | Line 80: | ||
</source> | </source> | ||
=== Each left and each right === | |||
A common problem is pairing up each [[element]] of one [[argument]] with all the elements of another argument. Because of scalar extension, [[enclose|making one argument a scalar]] accomplishes this: | |||
<source lang=apl> | |||
1 2 3,¨⊂100 200 | |||
┌─────────┬─────────┬─────────┐ | |||
│1 100 200│2 100 200│3 100 200│ | |||
└─────────┴─────────┴─────────┘ | |||
(⊂1 2 3),¨100 200 | |||
┌─────────┬─────────┐ | |||
│1 2 3 100│1 2 3 200│ | |||
└─────────┴─────────┘ | |||
</source> | |||
For [[scalar function]]s, explicit use of the [[Each]] operator is unnecessary: | |||
<source lang=apl> | |||
1 2 3+⊂100 200 | |||
┌───────┬───────┬───────┐ | |||
│101 201│102 202│103 203│ | |||
└───────┴───────┴───────┘ | |||
(⊂1 2 3)+100 200 | |||
┌───────────┬───────────┐ | |||
│101 102 103│201 202 203│ | |||
└───────────┴───────────┘ | |||
</source> | |||
[[Bind]]ing one argument to the function also works, but this always requires the Each operator: | |||
<source lang=apl> | |||
1 2 3∘,¨100 200 | |||
┌─────────┬─────────┐ | |||
│1 2 3 100│1 2 3 200│ | |||
└─────────┴─────────┘ | |||
(,∘100 200)¨1 2 3 | |||
┌─────────┬─────────┬─────────┐ | |||
│1 100 200│2 100 200│3 100 200│ | |||
└─────────┴─────────┴─────────┘ | |||
</source> | |||
{{APL features}}[[Category:Function characteristics]][[Category:Conformability]] | {{APL features}}[[Category:Function characteristics]][[Category:Conformability]] |