In general, the convention in Julia is that a lower-case function like range
may produce a variety of different types depending on its arguments, while CamelCase in Julia is used for specific types and constructors thereof.
Both LinRange
and StepRangeLen
are examples of AbstractRange
types. Although you can call their constructors directly in rare cases where you need a specific range type, it is generally preferable to call the range
function and let it determine the appropriate type from the types of the arguments.
For typical range of floating-point values, range
returns a StepRangeLen
:
julia> range(0,3,length=4)
0.0:1.0:3.0
julia> typeof(ans)
StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}
For an integer step
, it returns a StepRange
:
julia> range(0,4,step=2)
0:2:4
julia> typeof(ans)
StepRange{Int64,Int64}
For non-numeric types, however, e.g. a range between two vectors, it returns a LinRange
:
julia> range([1,2], [3,4], length=10)
10-element LinRange{Array{Int64,1}}:
[1.0, 2.0],[1.22222, 2.22222],…,[2.77778, 3.77778],[3.0, 4.0]
because LinRange
is more generic (https://github.com/JuliaLang/julia/pull/18777).
The documentation of the range
function needs work, however (https://github.com/JuliaLang/julia/issues/33798).