Index origin: Difference between revisions

Jump to navigation Jump to search
15 bytes added ,  22:25, 30 October 2019
no edit summary
Miraheze>Adám Brudzewsky
m (Text replacement - "</code>" to "</source>")
Miraheze>Adám Brudzewsky
No edit summary
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]] <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, [[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</source> in APL is referred to in English as the "first" element.
{{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</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 [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</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>.
<pre class=apl>
<source lang=apl>
       ⎕IO←0
       ⎕IO←0
       ⍳4
       ⍳4
Line 9: Line 9:
       ⍳4
       ⍳4
1 2 3 4
1 2 3 4
</pre>
</source>


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</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]].

Navigation menu