Take: Difference between revisions
Jump to navigation
Jump to search
m
Reverted edits by Marshall (talk) to last revision by Adám Brudzewsky
Miraheze>Marshall |
Miraheze>Marshall m (Reverted edits by Marshall (talk) to last revision by Adám Brudzewsky) |
||
Line 12: | Line 12: | ||
The left argument to length specifies a length, and not an index. It does not depend on [[index origin]]. | The left argument to length specifies a length, and not an index. It does not depend on [[index origin]]. | ||
A length which is larger than the argument length causes [[Fill element|fills]] to be inserted. The alignment remains the same: if two different positive arguments are used to take from an array, the one which is closer to zero gives a [[prefix]] of the other result. If they are both negative, it is a [[suffix]] instead | A length which is larger than the argument length causes [[Fill element|fills]] to be inserted. The alignment remains the same: if two different positive arguments are used to take from an array, the one which is closer to zero gives a [[prefix]] of the other result. If they are both negative, it is a [[suffix]] instead. | ||
<source lang=apl> | <source lang=apl> | ||
8 ↑ 5 4 3 2 1 | 8 ↑ 5 4 3 2 1 | ||
Line 19: | Line 19: | ||
0 0 0 5 4 3 2 1 | 0 0 0 5 4 3 2 1 | ||
</source> | </source> | ||
{{Works in|[[Dyalog APL]], [[ngn/ | {{Works in|[[Dyalog APL]], [[ngn/APL]]}} | ||
A higher-[[rank]] array can be shortened by using a left argument with one element for each axis: | A higher-[[rank]] array can be shortened by using a left argument with one element for each axis: | ||
Line 30: | Line 30: | ||
└───┴───┴───┘ | └───┴───┴───┘ | ||
</source> | </source> | ||
{{Works in|[[Dyalog APL]], [[dzaima/APL]], [[ngn/ | {{Works in|[[Dyalog APL]], [[dzaima/APL]], [[ngn/APL]]}} | ||
In languages with the SHARP APL extension, the left argument can be shortened. This causes leading axes of the right argument to be modified while trailing axes are ignored. | In languages with the SHARP APL extension, the left argument can be shortened. This causes leading axes of the right argument to be modified while trailing axes are ignored. | ||
Line 41: | Line 41: | ||
└───┴───┴───┴───┴───┘ | └───┴───┴───┴───┴───┘ | ||
</source> | </source> | ||
{{Works in|[[Dyalog APL]], [[ngn/ | {{Works in|[[Dyalog APL]], [[ngn/APL]]}} | ||
An [[Function axis|axis]] may be specified to apply left argument elements to specific axes of the right argument. Here the last axis is specified in order to take two columns of the argument. | An [[Function axis|axis]] may be specified to apply left argument elements to specific axes of the right argument. Here the last axis is specified in order to take two columns of the argument. | ||
Line 72: | Line 72: | ||
When Take is called with [[Function axis|axis]], the axis determines how elements of the left argument correspond to axes of the right argument. The left argument and axis are required to have rank no more than 1 and are treated as vectors. Their lengths must match, and be less than or equal to the rank of the right argument. Then each element of the left argument applies to the right argument axis given by the corresponding element of the axis vector. Each axis may only be specified once, and unspecified axes are left unchanged. | When Take is called with [[Function axis|axis]], the axis determines how elements of the left argument correspond to axes of the right argument. The left argument and axis are required to have rank no more than 1 and are treated as vectors. Their lengths must match, and be less than or equal to the rank of the right argument. Then each element of the left argument applies to the right argument axis given by the corresponding element of the axis vector. Each axis may only be specified once, and unspecified axes are left unchanged. | ||
== History == | == History == | ||
Take was present in [[APL\360]], but not in [[A Programming Language]], where the symbol (<code>↑</code>) was used for [[Rotate]].<ref>Iverson, Kenneth E. (1962). A Programming Language. Wiley. ISBN 978-0-471-43014-8.</ref> | |||
The [[Function axis|axis]] specification for Take was defined in [[APL2]]. It is shared by [[SHARP APL]] and [[Rationalized APL]], and continues to be supported in [[Dyalog APL]]. | The [[Function axis|axis]] specification for Take was defined in [[APL2]]. It is shared by [[SHARP APL]] and [[Rationalized APL]], and continues to be supported in [[Dyalog APL]]. | ||
[[SHARP APL 19.0]], released in 1987, extended Take to allow short left arguments. The choice to align left argument elements with the leading axes of the right argument was made according to the nascent [[leading axis theory]]: while a user may not have any preference for manipulating the earlier dimensions, this choice makes Take more flexible when used with the [[Rank operator]].<ref>Bernecky, Robert. [https://dl.acm.org/citation.cfm?id=55632 "An Introduction to Function Rank"]. APL88 Conference Proceedings. ''ACM SIGAPL Quote Quad'', 18(2), December 1987.</ref> This extension is also used in [[Dyalog APL]], [[J]], and [[ngn/ | [[SHARP APL 19.0]], released in 1987, extended Take to allow short left arguments. The choice to align left argument elements with the leading axes of the right argument was made according to the nascent [[leading axis theory]]: while a user may not have any preference for manipulating the earlier dimensions, this choice makes Take more flexible when used with the [[Rank operator]].<ref>Bernecky, Robert. [https://dl.acm.org/citation.cfm?id=55632 "An Introduction to Function Rank"]. APL88 Conference Proceedings. ''ACM SIGAPL Quote Quad'', 18(2), December 1987.</ref> This extension is also used in [[Dyalog APL]], [[J]], and [[ngn/APL]]. It was not adopted in [[ISO/IEC 13751:2001]]. | ||
== References == | == References == | ||
<references /> | <references /> |