@@ -46,36 +46,51 @@ function _colon(start::T, step, stop::T) where T
4646end
4747
4848"""
49- range(start; length, stop, step=1)
49+ range(start[, stop] ; length, stop, step=1)
5050
51- Given a starting value, construct a range either by length or from `start` to `stop`,
52- optionally with a given step (defaults to 1, a [`UnitRange`](@ref)).
53- One of `length` or `stop` is required. If `length`, `stop`, and `step` are all specified, they must agree.
51+ Given a starting value, construct a range by specifying any two of `stop`,
52+ `length`, and `step`. If `length`, `stop`, and `step` are all specified, they must agree.
5453
5554If `length` and `stop` are provided and `step` is not, the step size will be computed
5655automatically such that there are `length` linearly spaced elements in the range (a [`LinRange`](@ref)).
5756
5857If `step` and `stop` are provided and `length` is not, the overall range length will be computed
5958automatically such that the elements are `step` spaced (a [`StepRange`](@ref)).
6059
60+ `stop` may be specified as either a positional or keyword argument.
61+
6162# Examples
6263```jldoctest
63- julia> range(1, length=100)
64+ julia> range(1, step=1, length=100)
64651:100
6566
66- julia> range(1, stop=100)
67+ julia> range(1, step=1, stop=100)
67681:100
6869
6970julia> range(1, step=5, length=100)
70711:5:496
7172
7273julia> range(1, step=5, stop=100)
73741:5:96
75+
76+ julia> range(1, 10, length=101)
77+ 1.0:0.09:10.0
78+
79+ julia> range(1, 100, step=5)
80+ 1:5:96
7481```
7582"""
7683range (start; length:: Union{Integer,Nothing} = nothing , stop= nothing , step= nothing ) =
7784 _range (start, step, stop, length)
7885
86+ range (start, stop; length:: Union{Integer,Nothing} = nothing , step= nothing ) =
87+ _range2 (start, step, stop, length)
88+
89+ _range2 (start, :: Nothing , stop, :: Nothing ) =
90+ throw (ArgumentError (" At least one of `length` or `step` must be specified" ))
91+
92+ _range2 (start, step, stop, length) = _range (start, step, stop, length)
93+
7994# Range from start to stop: range(a, [step=s,] stop=b), no length
8095_range (start, step, stop, :: Nothing ) = (:)(start, step, stop)
8196_range (start, :: Nothing , stop, :: Nothing ) = (:)(start, stop)
0 commit comments