Index origin: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
Miraheze>Marshall
m (Text replacement - "<source" to "<syntaxhighlight")
 
(15 intermediate revisions by 6 users not shown)
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]] <code>⎕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 <code>⎕IO</code> in APL is referred to in English as the "first" element.
{{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]] <syntaxhighlight lang=apl inline>⎕IO</syntaxhighlight>. 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 <syntaxhighlight lang=apl inline>⎕IO</syntaxhighlight> 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 <code>⎕IO</code>.
The index origin affects both the handling of index arguments to functions (and other functionality like [[axis specification]]) and their results. For example, [[Index Generator]] creates results that begin with <syntaxhighlight lang=apl inline>⎕IO</syntaxhighlight>.
<pre class=apl>
<syntaxhighlight lang=apl>
       ⎕IO←0
       ⎕IO←0
       ⍳4
       ⍳4
Line 9: Line 9:
       ⍳4
       ⍳4
1 2 3 4
1 2 3 4
</pre>
</syntaxhighlight>


Any number could consistently be used for the index origin, but almost all APLs restrict the choice to 0 or 1. [[ngn/apl]] supports <code>⎕IO</code> but only allows it to have the value 0. Attempting to assign an unsupported value to <code>⎕IO</code> typically results in a [[DOMAIN ERROR]].
Any number could consistently be used for the index origin, but almost all APLs restrict the choice to 0 or 1. [[ngn/apl]] supports <syntaxhighlight lang=apl inline>⎕IO</syntaxhighlight> but only allows it to have the value 0. Attempting to assign an unsupported value to <syntaxhighlight lang=apl inline>⎕IO</syntaxhighlight> 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 <code>⎕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 <code>⎕IO</code> except where noted with <code>⍺</code> in which case the left argument does instead. For operators the dependence is noted.
The following functions depend on <syntaxhighlight lang=apl inline>⎕IO</syntaxhighlight> in at least some APLs. They are listed with the [[glyph]]s used for them in [[Dyalog APL]]. For functions, only the result depends on <syntaxhighlight lang=apl inline>⎕IO</syntaxhighlight> except where noted with <syntaxhighlight lang=apl inline>⍺</syntaxhighlight> 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 function]]s         !! [[Dyadic function]]s                         !! [[Operator]]s
|-
|-
| [[Iota]] (<code>⍳</code>)     || [[Index-Of]] (<code>⍳</code>)                || [[Key]] (<code>⌸</code>) argument to <code>⍺⍺</code>
| [[Index Generator]] (<syntaxhighlight lang=apl inline>⍳</syntaxhighlight>) || [[Index-Of]] (<syntaxhighlight lang=apl inline>⍳</syntaxhighlight>)                || [[Key]] (<syntaxhighlight lang=apl inline>⌸</syntaxhighlight>) argument to <syntaxhighlight lang=apl inline>⍺⍺</syntaxhighlight>
|-
|-
| [[Roll]] (<code>?</code>)    || [[Deal]] (<code>?</code>)                    || [[At]] (<code>@</code>) result of <code>⍵⍵</code>
| [[Roll]] (<syntaxhighlight lang=apl inline>?</syntaxhighlight>)    || [[Deal]] (<syntaxhighlight lang=apl inline>?</syntaxhighlight>)                    || [[At]] (<syntaxhighlight lang=apl inline>@</syntaxhighlight>) result of <syntaxhighlight lang=apl inline>⍵⍵</syntaxhighlight>
|-
|-
| [[Grade]] (<code>⍒⍋</code>)  || (<code>⍒⍋</code>)                            ||
| [[Grade]] (<syntaxhighlight lang=apl inline>⍒⍋</syntaxhighlight>)  || (<syntaxhighlight lang=apl inline>⍒⍋</syntaxhighlight>)                            ||
|-
|-
| [[Indices]] (<code>⍸</code>)  || [[Interval Index]] (<code>⍸</code>)          ||
| [[Indices]] (<syntaxhighlight lang=apl inline>⍸</syntaxhighlight>)  || [[Interval Index]] (<syntaxhighlight lang=apl inline>⍸</syntaxhighlight>)          ||
|-
|-
|                              || [[Transpose]] (<code>⍉</code>) <code>⍺</code> ||
|                              || [[Transpose]] (<syntaxhighlight lang=apl inline>⍉</syntaxhighlight>) <syntaxhighlight lang=apl inline>⍺</syntaxhighlight> ||
|-
|-
|                              || [[Pick]] (<code>⊃</code>) <code>⍺</code>      ||
|                              || [[Pick]] (<syntaxhighlight lang=apl inline>⊃</syntaxhighlight>) <syntaxhighlight lang=apl inline>⍺</syntaxhighlight>      ||
|-
|-
|                              || [[Squad]] (<code>⌷</code>) <code>⍺</code>    ||
|                              || [[Squad]] (<syntaxhighlight lang=apl inline>⌷</syntaxhighlight>) <syntaxhighlight lang=apl inline>⍺</syntaxhighlight>    ||
|}
|}


Additionally, [[indexing]] with brackets and [[axis specification]] depend on index origin.
Additionally, [[Bracket indexing|indexing]] with brackets and [[axis specification]] depend on index origin.


== External links ==
== External links ==
Line 43: Line 43:
=== Articles ===
=== Articles ===


* [https://en.wikipedia.org/wiki/Array_data_type#Index_origin Wikipedia]
* [[wikipedia:Array data type#Index origin|Index origin]]
 
* [https://www.jsoftware.com/papers/indexorigin.htm Is Index Origin 0 a Hindrance?]
* [https://www.jsoftware.com/papers/indexorigin.htm Is Index Origin 0 a Hindrance?]


Line 54: Line 53:


* [https://help.dyalog.com/latest/index.htm#Language/System%20Functions/io.htm Dyalog]
* [https://help.dyalog.com/latest/index.htm#Language/System%20Functions/io.htm Dyalog]
* [http://microapl.com/apl_help/ch_020_070_380.htm APLX]
* [http://microapl.com/apl_help/ch_020_070_380.htm APLX]
 
{{APL built-ins}}[[Category:System constants]]
{{APL built-ins}}

Latest revision as of 22:05, 10 September 2022

⎕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, Index Generator creates results that 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
Index Generator () 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.

External links

Articles

Lessons

Documentation

APL built-ins [edit]
Primitives (Timeline) Functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare RootRound
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
Non-Scalar
Structural ShapeReshapeTallyDepthRavelEnlistTableCatenateReverseRotateTransposeRazeMixSplitEncloseNestCut (K)PairLinkPartitioned EnclosePartition
Selection FirstPickTakeDropUniqueIdentityStopSelectReplicateExpandSet functions (IntersectionUnionWithout) ∙ Bracket indexingIndexCartesian ProductSort
Selector Index generatorGradeIndex OfInterval IndexIndicesDealPrefix and suffix vectors
Computational MatchNot MatchMembershipFindNub SieveEncodeDecodeMatrix InverseMatrix DivideFormatExecuteMaterialiseRange
Operators Monadic EachCommuteConstantReplicateExpandReduceWindowed ReduceScanOuter ProductKeyI-BeamSpawnFunction axisIdentity (Null, Ident)
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner ProductDeterminantPowerAtUnderRankDepthVariantStencilCutDirect definition (operator)Identity (Lev, Dex)
Quad names Index originComparison toleranceMigration levelAtomic vector