Index origin: Difference between revisions

Jump to navigation Jump to search
25 bytes removed ,  15:21, 20 November 2019
m
15 revisions imported: Migrate from miraheze
Miraheze>Adám Brudzewsky
m (Text replacement - "</code>" to "</source>")
m (15 revisions imported: Migrate from miraheze)
(6 intermediate revisions by 2 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]] <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.
{{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.


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


{| 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]] (<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>
| [[Iota]] (<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>
Line 43: Line 43:
=== Articles ===
=== Articles ===


* [https://en.wikipedia.org/wiki/Array_data_type#Index_origin Wikipedia]
* [[wikipedia:Array_data_type#Index_origin|Wikipedia]]
 
* [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}}
{{APL built-ins}}

Navigation menu