2,954
edits
Miraheze>Marshall |
(→Documentation: BQN link) |
||
(11 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
{{ | {{Built-ins|Reverse|⌽|⊖}} is a [[monadic function]] which reorders [[elements]] of the argument to go in the opposite direction along a specified [[axis]]. The name Reverse is typically used for the primitive <source lang=apl inline>⌽</source>, which reverses along the last axis, while <source lang=apl inline>⊖</source>, which reverses along the first axis, is called "Reverse First", "Reverse-down", or similar. In APLs with [[function axis]], either form may use a specified axis which overrides this default choice of axis. In the [[leading axis model]], specifying an axis is discouraged in favor of using <source lang=apl inline>⊖</source> with the [[Rank operator]]. | ||
== Examples == | == Examples == | ||
Line 28: | Line 28: | ||
Reverse with a [[specified axis]] can reverse along any of the three dimensions of the array below. | Reverse with a [[specified axis]] can reverse along any of the three dimensions of the array below. | ||
<source lang=apl> | <source lang=apl> | ||
⎕←a←2 3 6⍴⍳36 | |||
1 2 3 4 5 6 | 1 2 3 4 5 6 | ||
7 8 9 10 11 12 | 7 8 9 10 11 12 | ||
Line 99: | Line 99: | ||
⍺ ← ¯1+≢⍴⍵ ⍝ Assume last axis | ⍺ ← ¯1+≢⍴⍵ ⍝ Assume last axis | ||
l ← ⍺ ⌷ ⍴⍵ ⍝ Length of reversed axis | l ← ⍺ ⌷ ⍴⍵ ⍝ Length of reversed axis | ||
( | (⊂l-1+⍳l) ⌷[⍺] ⍵ ⍝ Reverse with indexing | ||
} | } | ||
</source> | </source> | ||
Line 111: | Line 111: | ||
=== Documentation === | === Documentation === | ||
* [ | * [https://help.dyalog.com/latest/index.htm#Language/Primitive%20Functions/Reverse.htm Dyalog] | ||
* [http://microapl.com/apl_help/ch_020_020_510.htm APLX] | * [http://microapl.com/apl_help/ch_020_020_510.htm APLX] | ||
* J [https://www.jsoftware.com/help/dictionary/d231.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/bardot NuVoc] (only first-axis reverse exists) | * J [https://www.jsoftware.com/help/dictionary/d231.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/bardot NuVoc] (only first-axis reverse exists) | ||
* [https://mlochbaum.github.io/BQN/doc/reverse.html BQN] | |||
{{APL built-ins}}[[Category:Primitive functions]][[Category:Functions with first- and last-axis forms]] |