Index origin: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
m (Text replacement - "</source>" to "</syntaxhighlight>")
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 [[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.
{{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</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 <source 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, [[Index Generator]] creates results that 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, [[Index Generator]] creates results that begin with <source lang=apl inline>⎕IO</syntaxhighlight>.
<source lang=apl>
<source lang=apl>
       ⎕IO←0
       ⎕IO←0
Line 9: Line 9:
       ⍳4
       ⍳4
1 2 3 4
1 2 3 4
</source>
</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 <source lang=apl inline>⎕IO</source> but only allows it to have the value 0. Attempting to assign an unsupported value to <source lang=apl inline>⎕IO</source> 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 <source lang=apl inline>⎕IO</syntaxhighlight> but only allows it to have the value 0. Attempting to assign an unsupported value to <source 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 <source lang=apl inline>⎕IO</source> 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 <source lang=apl inline>⎕IO</source> except where noted with <source lang=apl inline>⍺</source> in which case the left argument does instead. For operators the dependence is noted.
The following functions depend on <source 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 <source lang=apl inline>⎕IO</syntaxhighlight> except where noted with <source 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 function]]s        !! [[Dyadic function]]s                          !! [[Operator]]s
! [[Monadic function]]s        !! [[Dyadic function]]s                          !! [[Operator]]s
|-
|-
| [[Index Generator]] (<source lang=apl inline>⍳</source>) || [[Index-Of]] (<source lang=apl inline>⍳</source>)                || [[Key]] (<source lang=apl inline>⌸</source>) argument to <source lang=apl inline>⍺⍺</source>
| [[Index Generator]] (<source lang=apl inline>⍳</syntaxhighlight>) || [[Index-Of]] (<source lang=apl inline>⍳</syntaxhighlight>)                || [[Key]] (<source lang=apl inline>⌸</syntaxhighlight>) argument to <source lang=apl inline>⍺⍺</syntaxhighlight>
|-
|-
| [[Roll]] (<source lang=apl inline>?</source>)    || [[Deal]] (<source lang=apl inline>?</source>)                    || [[At]] (<source lang=apl inline>@</source>) result of <source lang=apl inline>⍵⍵</source>
| [[Roll]] (<source lang=apl inline>?</syntaxhighlight>)    || [[Deal]] (<source lang=apl inline>?</syntaxhighlight>)                    || [[At]] (<source lang=apl inline>@</syntaxhighlight>) result of <source lang=apl inline>⍵⍵</syntaxhighlight>
|-
|-
| [[Grade]] (<source lang=apl inline>⍒⍋</source>)  || (<source lang=apl inline>⍒⍋</source>)                            ||
| [[Grade]] (<source lang=apl inline>⍒⍋</syntaxhighlight>)  || (<source lang=apl inline>⍒⍋</syntaxhighlight>)                            ||
|-
|-
| [[Indices]] (<source lang=apl inline>⍸</source>)  || [[Interval Index]] (<source lang=apl inline>⍸</source>)          ||
| [[Indices]] (<source lang=apl inline>⍸</syntaxhighlight>)  || [[Interval Index]] (<source lang=apl inline>⍸</syntaxhighlight>)          ||
|-
|-
|                              || [[Transpose]] (<source lang=apl inline>⍉</source>) <source lang=apl inline>⍺</source> ||
|                              || [[Transpose]] (<source lang=apl inline>⍉</syntaxhighlight>) <source lang=apl inline>⍺</syntaxhighlight> ||
|-
|-
|                              || [[Pick]] (<source lang=apl inline>⊃</source>) <source lang=apl inline>⍺</source>      ||
|                              || [[Pick]] (<source lang=apl inline>⊃</syntaxhighlight>) <source lang=apl inline>⍺</syntaxhighlight>      ||
|-
|-
|                              || [[Squad]] (<source lang=apl inline>⌷</source>) <source lang=apl inline>⍺</source>    ||
|                              || [[Squad]] (<source lang=apl inline>⌷</syntaxhighlight>) <source lang=apl inline>⍺</syntaxhighlight>    ||
|}
|}



Revision as of 21:59, 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 <source 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 English language uses an index origin of one: thus the element with index <source 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, Index Generator creates results that begin with <source lang=apl inline>⎕IO</syntaxhighlight>. <source lang=apl>

     ⎕IO←0
     ⍳4

0 1 2 3

     ⎕IO←1
     ⍳4

1 2 3 4 </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 <source lang=apl inline>⎕IO</syntaxhighlight> but only allows it to have the value 0. Attempting to assign an unsupported value to <source 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.

Functions which depend on index origin

The following functions depend on <source lang=apl inline>⎕IO</syntaxhighlight> 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</syntaxhighlight> except where noted with <source lang=apl inline>⍺</syntaxhighlight> in which case the left argument does instead. For operators the dependence is noted.

Monadic functions Dyadic functions Operators
Index Generator (<source lang=apl inline>⍳</syntaxhighlight>) Index-Of (<source lang=apl inline>⍳</syntaxhighlight>) Key (<source lang=apl inline>⌸</syntaxhighlight>) argument to <source lang=apl inline>⍺⍺</syntaxhighlight>
Roll (<source lang=apl inline>?</syntaxhighlight>) Deal (<source lang=apl inline>?</syntaxhighlight>) At (<source lang=apl inline>@</syntaxhighlight>) result of <source lang=apl inline>⍵⍵</syntaxhighlight>
Grade (<source lang=apl inline>⍒⍋</syntaxhighlight>) (<source lang=apl inline>⍒⍋</syntaxhighlight>)
Indices (<source lang=apl inline>⍸</syntaxhighlight>) Interval Index (<source lang=apl inline>⍸</syntaxhighlight>)
Transpose (<source lang=apl inline>⍉</syntaxhighlight>) <source lang=apl inline>⍺</syntaxhighlight>
Pick (<source lang=apl inline>⊃</syntaxhighlight>) <source lang=apl inline>⍺</syntaxhighlight>
Squad (<source lang=apl inline>⌷</syntaxhighlight>) <source lang=apl inline>⍺</syntaxhighlight>

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