Purpose of the Range object


#1

Hi All,

I wanted to return values of Range type so that it becomes clear in the end-users mind that we are talking about a number range and will be used as a pages iterator. But, I realize the only way to create a Range is with the function range. The Range object per-se is not documented and just mapped to UnionAll.

Is it the right usage or Range object? Or is it intended more from a set theoretic relationship like a domain range [1,55.5) use case. I see various mathematical and statistical operations on it.

I can return a Tuple{Int,Int} or Pair{Int, Int} but both do not provide the same clarity as Range.

regards,

Sambit


#2

Range is an abstract type, so a value cannot have this type, only a subtype of Range.

For integers, UnitRange should be fine. You can use the a:b constructor. The most commonly understood meaning is “all integers between a and b, inclusive”, but you can use it for anything you like.

For floating point intervals, various packages have different implementations, with different semantics.


#3

Unfortunately, the Range object concrete types are not documented clearly. From the REPL help.

help?> UnitRange
search: UnitRange AbstractUnitRange

  No documentation found.

  Base.UnitRange is of type UnionAll.

     Summary
    ≡≡≡≡≡≡≡≡≡

  struct UnionAll <: Type{T}

     Fields
    ≡≡≡≡≡≡≡≡

  var  :: TypeVar
  body :: Any

     Supertype Hierarchy
    ≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡

  UnionAll <: Type{T} <: Any

help?> AbstractUnitRange
search: AbstractUnitRange

  No documentation found.

  Base.AbstractUnitRange is of type UnionAll.

     Summary
    ≡≡≡≡≡≡≡≡≡

  struct UnionAll <: Type{T}

     Fields
    ≡≡≡≡≡≡≡≡

  var  :: TypeVar
  body :: Any

     Supertype Hierarchy
    ≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡

  UnionAll <: Type{T} <: Any

#4

I am sure pull requests for documentation would be welcome; however, most of the documentation for UnitRange would be found in the manual where : is discussed. These would be a good start.


#5

Thanks @Tamas_Papp

I have created an issue as well. https://github.com/JuliaLang/julia/issues/23421