Range

From APL Wiki
Jump to navigation Jump to search
...

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 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 ..), Extended Dyalog APL, and dzaima/APL.

Basic usage

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.

      38
3 4 5 6 7 8
      44
4
      5¯5
5 4 3 2 1 0 ¯1 ¯2 ¯3 ¯4 ¯5

It should be noted that, since the exact definition of Range has never been standardised, a different implementation might as well choose to return or even throw a DOMAIN ERROR for XY when X>Y.

Extensions

NARS2000 supports step size and multi-dimensional range (giving the result similar to multi-dimensional Index Generator):

      3 2..10  ⍝ Start, step, and end values
3 5 7 9
      (3 4)..6  ⍝ Two start values, so the result is two-dimensional and nested
┌───┬───┬───┐
3 43 53 6
├───┼───┼───┤
4 44 54 6
├───┼───┼───┤
5 45 55 6
├───┼───┼───┤
6 46 56 6
└───┴───┴───┘
      (6 7)2..2  ⍝ Two start values with step size; the sign of step size is ignored
┌───┬───┬───┐
6 76 56 3
├───┼───┼───┤
4 74 54 3
├───┼───┼───┤
2 72 52 3
└───┴───┴───┘
Works in: NARS2000

In Extended Dyalog APL, the extension is focused on making it easier to produce integer or character vector constants:

      110 20100 800
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'
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ

External links

Documentation


APL built-ins [edit]
Primitive functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare Root
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
Non-Scalar
Structural ShapeReshapeTallyDepthRavelEnlistTableCatenateReverseRotateTransposeRazeMixSplitEncloseNestCut (K)PairLinkPartitioned EnclosePartition
Selection FirstPickTakeDropUniqueIdentitySelectReplicateExpandSet functions (IntersectionUnionWithout) ∙ Bracket indexingIndex
Selector Index generatorGradeIndex OfInterval IndexIndicesDeal
Computational MatchNot MatchMembershipFindNub SieveEncodeDecodeMatrix InverseMatrix DivideFormatExecuteMaterialiseRange
Primitive operators Monadic EachCommuteConstantReplicateExpandReduceWindowed ReduceScanOuter ProductKeyI-beamSpawnFunction axis
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Atop, Over) ∙ Inner ProductPowerAtUnderRankDepthVariantStencilCut (J)
Quad names
Arrays Index originMigration levelAtomic vector
Functions Case convertUnicode convert
Operators SearchReplace