Index origin: Difference between revisions
Miraheze>Marshall mNo edit summary |
Miraheze>Marshall No edit summary |
||
Line 1: | Line 1: | ||
{{Built-in|Index origin|⎕IO}} is the number used for the first [[index]] along each [[axis]] of an array. Many APLs allow the user to configure index origin using the [[system variable]] <source lang=apl inline>⎕IO</source>. Even array languages which do not have such a configuration parameter must make a choice of index origin; for example, [[A+]] and [[J]] use a non-configurable index origin of 0. The [ | {{Built-in|Index origin|⎕IO}} is the number used for the first [[index]] along each [[axis]] of an array. Many APLs allow the user to configure index origin using the [[system variable]] <source lang=apl inline>⎕IO</source>. Even array languages which do not have such a configuration parameter must make a choice of index origin; for example, [[A+]] and [[J]] use a non-configurable index origin of 0. The [[wikipedia:English language|English language]] uses an index origin of one: thus the element with index <source lang=apl inline>⎕IO</source> in APL is referred to in English as the "first" element. | ||
The index origin affects both the handling of index arguments to functions (and other functionality like [[axis specification]]) and their results. For example, [[Iota]] (or "Index Generator") creates results which begin with <source lang=apl inline>⎕IO</source>. | The index origin affects both the handling of index arguments to functions (and other functionality like [[axis specification]]) and their results. For example, [[Iota]] (or "Index Generator") creates results which begin with <source lang=apl inline>⎕IO</source>. |
Revision as of 14:54, 14 November 2019
⎕IO
|
Index origin (⎕IO
) is the number used for the first index along each axis of an array. Many APLs allow the user to configure index origin using the system variable ⎕IO
. Even array languages which do not have such a configuration parameter must make a choice of index origin; for example, A+ and J use a non-configurable index origin of 0. The English language uses an index origin of one: thus the element with index ⎕IO
in APL is referred to in English as the "first" element.
The index origin affects both the handling of index arguments to functions (and other functionality like axis specification) and their results. For example, Iota (or "Index Generator") creates results which begin with ⎕IO
.
⎕IO←0 ⍳4 0 1 2 3 ⎕IO←1 ⍳4 1 2 3 4
Any number could consistently be used for the index origin, but almost all APLs restrict the choice to 0 or 1. ngn/apl supports ⎕IO
but only allows it to have the value 0. Attempting to assign an unsupported value to ⎕IO
typically results in a DOMAIN ERROR.
The choice of which numbers are indices is subjective and must be made by the language designer. In some cases there is no clear decision: Interval Index and Occurrence Count each have natural definitions that depend on index origin, and natural definitions that do not.
Functions which depend on index origin
The following functions depend on ⎕IO
in at least some APLs. They are listed with the glyphs used for them in Dyalog APL. For functions, only the result depends on ⎕IO
except where noted with ⍺
in which case the left argument does instead. For operators the dependence is noted.
Monadic functions | Dyadic functions | Operators |
---|---|---|
Iota (⍳ ) |
Index-Of (⍳ ) |
Key (⌸ ) argument to ⍺⍺
|
Roll (? ) |
Deal (? ) |
At (@ ) result of ⍵⍵
|
Grade (⍒⍋ ) |
(⍒⍋ ) |
|
Indices (⍸ ) |
Interval Index (⍸ ) |
|
Transpose (⍉ ) ⍺ |
||
Pick (⊃ ) ⍺ |
||
Squad (⌷ ) ⍺ |
Additionally, indexing with brackets and axis specification depend on index origin.