Index origin: Difference between revisions
Jump to navigation
Jump to search
Miraheze>Marshall |
Miraheze>Adám Brudzewsky m (Text replacement - "<code>" to "<source lang=apl inline>") |
||
Line 1: | Line 1: | ||
{{Primitive|⎕IO|Index origin}} 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]] < | {{Primitive|⎕IO|Index origin}} 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</code>. Even array languages which do not have such a configuration parameter must make a choice of index origin; for example, [[J]] uses a non-configurable index origin of 0. The [https://en.wikipedia.org/wiki/English_language English language] uses an index origin of one: thus the element with index <source lang=apl inline>⎕IO</code> 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 < | 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</code>. | ||
<pre class=apl> | <pre class=apl> | ||
⎕IO←0 | ⎕IO←0 | ||
Line 11: | Line 11: | ||
</pre> | </pre> | ||
Any number could consistently be used for the index origin, but almost all APLs restrict the choice to 0 or 1. [[ngn/apl]] supports < | Any number could consistently be used for the index origin, but almost all APLs restrict the choice to 0 or 1. [[ngn/apl]] supports <source lang=apl inline>⎕IO</code> but only allows it to have the value 0. Attempting to assign an unsupported value to <source lang=apl inline>⎕IO</code> 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. | 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. | ||
Line 17: | Line 17: | ||
== Functions which depend on index origin == | == Functions which depend on index origin == | ||
The following functions depend on < | The following functions depend on <source lang=apl inline>⎕IO</code> in at least some APLs. They are listed with the [[glyphs]] used for them in [[Dyalog APL]]. For functions, only the result depends on <source lang=apl inline>⎕IO</code> except where noted with <source lang=apl inline>⍺</code> in which case the left argument does instead. For operators the dependence is noted. | ||
{| class="wikitable c" style="margin:1em auto" | {| class="wikitable c" style="margin:1em auto" | ||
! [[Monadic functions]] !! [[Dyadic functions]] !! [[Operators]] | ! [[Monadic functions]] !! [[Dyadic functions]] !! [[Operators]] | ||
|- | |- | ||
| [[Iota]] (< | | [[Iota]] (<source lang=apl inline>⍳</code>) || [[Index-Of]] (<source lang=apl inline>⍳</code>) || [[Key]] (<source lang=apl inline>⌸</code>) argument to <source lang=apl inline>⍺⍺</code> | ||
|- | |- | ||
| [[Roll]] (< | | [[Roll]] (<source lang=apl inline>?</code>) || [[Deal]] (<source lang=apl inline>?</code>) || [[At]] (<source lang=apl inline>@</code>) result of <source lang=apl inline>⍵⍵</code> | ||
|- | |- | ||
| [[Grade]] (< | | [[Grade]] (<source lang=apl inline>⍒⍋</code>) || (<source lang=apl inline>⍒⍋</code>) || | ||
|- | |- | ||
| [[Indices]] (< | | [[Indices]] (<source lang=apl inline>⍸</code>) || [[Interval Index]] (<source lang=apl inline>⍸</code>) || | ||
|- | |- | ||
| || [[Transpose]] (< | | || [[Transpose]] (<source lang=apl inline>⍉</code>) <source lang=apl inline>⍺</code> || | ||
|- | |- | ||
| || [[Pick]] (< | | || [[Pick]] (<source lang=apl inline>⊃</code>) <source lang=apl inline>⍺</code> || | ||
|- | |- | ||
| || [[Squad]] (< | | || [[Squad]] (<source lang=apl inline>⌷</code>) <source lang=apl inline>⍺</code> || | ||
|} | |} | ||