4,494
edits
m (Text replacement - "</source>" to "</syntaxhighlight>") |
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]] < | {{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, [[Index Generator]] creates results that 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, [[Index Generator]] creates results that begin with <syntaxhighlight lang=apl inline>⎕IO</syntaxhighlight>. | ||
< | <syntaxhighlight lang=apl> | ||
⎕IO←0 | ⎕IO←0 | ||
⍳4 | ⍳4 | ||
Line 11: | Line 11: | ||
</syntaxhighlight> | </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 < | 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 < | 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 function]]s !! [[Dyadic function]]s !! [[Operator]]s | ! [[Monadic function]]s !! [[Dyadic function]]s !! [[Operator]]s | ||
|- | |- | ||
| [[Index Generator]] (< | | [[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]] (< | | [[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]] (< | | [[Grade]] (<syntaxhighlight lang=apl inline>⍒⍋</syntaxhighlight>) || (<syntaxhighlight lang=apl inline>⍒⍋</syntaxhighlight>) || | ||
|- | |- | ||
| [[Indices]] (< | | [[Indices]] (<syntaxhighlight lang=apl inline>⍸</syntaxhighlight>) || [[Interval Index]] (<syntaxhighlight lang=apl inline>⍸</syntaxhighlight>) || | ||
|- | |- | ||
| || [[Transpose]] (< | | || [[Transpose]] (<syntaxhighlight lang=apl inline>⍉</syntaxhighlight>) <syntaxhighlight lang=apl inline>⍺</syntaxhighlight> || | ||
|- | |- | ||
| || [[Pick]] (< | | || [[Pick]] (<syntaxhighlight lang=apl inline>⊃</syntaxhighlight>) <syntaxhighlight lang=apl inline>⍺</syntaxhighlight> || | ||
|- | |- | ||
| || [[Squad]] (< | | || [[Squad]] (<syntaxhighlight lang=apl inline>⌷</syntaxhighlight>) <syntaxhighlight lang=apl inline>⍺</syntaxhighlight> || | ||
|} | |} | ||