4,500
edits
No edit summary |
m (Text replacement - "</source>" to "</syntaxhighlight>") |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{Built-ins|Range|…| | :''This page is about the dyadic primitive function. "Range" refers to [[Unique]] in K and [[Index Generator]] in BQN.'' | ||
{{Built-ins|Range|…|..}} or '''Sequence''' is a [[dyadic]] [[primitive function]] which creates a [[vector]] of consecutive integers based on the start and end values given by its [[argument|arguments]]. It serves as an [[index origin]]-agnostic alternative to [[Index Generator]] for creating a range of numbers. Range is currently implemented in [[NARS2000]] (using the digraph <syntaxhighlight lang=apl inline>..</syntaxhighlight>), [[Extended Dyalog APL]], and [[dzaima/APL]]. | |||
== Basic usage == | == Basic usage == | ||
Line 5: | Line 7: | ||
If both arguments are [[scalar]] integers, Range creates the consecutive range between the two arguments inclusive. If the left argument is greater than the right argument, the result becomes a decreasing sequence. | If both arguments are [[scalar]] integers, Range creates the consecutive range between the two arguments inclusive. If the left argument is greater than the right argument, the result becomes a decreasing sequence. | ||
< | <syntaxhighlight lang=apl> | ||
3…8 | 3…8 | ||
3 4 5 6 7 8 | 3 4 5 6 7 8 | ||
Line 12: | Line 14: | ||
5…¯5 | 5…¯5 | ||
5 4 3 2 1 0 ¯1 ¯2 ¯3 ¯4 ¯5 | 5 4 3 2 1 0 ¯1 ¯2 ¯3 ¯4 ¯5 | ||
</ | </syntaxhighlight>{{Works in|[[NARS2000]], [[Extended Dyalog APL]], [[dzaima/APL]]}} | ||
It should be noted that, since the exact definition of Range has never been standardised, a different implementation might as well choose to return < | It should be noted that, since the exact definition of Range has never been standardised, a different implementation might as well choose to return <syntaxhighlight lang=apl inline>⍬</syntaxhighlight> or even throw a [[DOMAIN ERROR]] for <syntaxhighlight lang=apl inline>X…Y</syntaxhighlight> when <syntaxhighlight lang=apl inline>X>Y</syntaxhighlight>. | ||
== Extensions == | == Extensions == | ||
Line 20: | Line 22: | ||
[[NARS2000]] supports step size and multi-dimensional range (giving the result similar to multi-dimensional [[Index Generator]]): | [[NARS2000]] supports step size and multi-dimensional range (giving the result similar to multi-dimensional [[Index Generator]]): | ||
< | <syntaxhighlight lang=apl> | ||
3 2..10 ⍝ Start, step, and end values | 3 2..10 ⍝ Start, step, and end values | ||
3 5 7 9 | 3 5 7 9 | ||
Line 41: | Line 43: | ||
│2 7│2 5│2 3│ | │2 7│2 5│2 3│ | ||
└───┴───┴───┘ | └───┴───┴───┘ | ||
</ | </syntaxhighlight>{{Works in|[[NARS2000]]}} | ||
In [[Extended Dyalog APL]], the extension is focused on making it easier to produce integer or character vector constants: | In [[Extended Dyalog APL]], the extension is focused on making it easier to produce integer or character vector constants: | ||
< | <syntaxhighlight lang=apl> | ||
1…10 20…100 80…0 | 1…10 20…100 80…0 | ||
1 2 3 4 5 6 7 8 9 10 20 30 40 50 60 70 80 90 100 80 60 40 20 0 | 1 2 3 4 5 6 7 8 9 10 20 30 40 50 60 70 80 90 100 80 60 40 20 0 | ||
'a'…'zA'…'Z' | 'a'…'zA'…'Z' | ||
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ | abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ | ||
</ | </syntaxhighlight>{{Works in|[[Extended Dyalog APL]]}} | ||
== External links == | == External links == |