@@ -46,7 +46,7 @@ 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
5151Given a starting value, construct a range either by length or from `start` to `stop`,
5252optionally with a given step (defaults to 1, a [`UnitRange`](@ref)).
@@ -58,6 +58,8 @@ automatically such that there are `length` linearly spaced elements in the range
5858If `step` and `stop` are provided and `length` is not, the overall range length will be computed
5959automatically such that the elements are `step` spaced (a [`StepRange`](@ref)).
6060
61+ `stop` may be specified as either a positional or keyword argument.
62+
6163# Examples
6264```jldoctest
6365julia> range(1, length=100)
@@ -71,11 +73,28 @@ julia> range(1, step=5, length=100)
7173
7274julia> range(1, step=5, stop=100)
73751:5:96
76+
77+ julia> range(1, 100)
78+ 1:100
79+
80+ julia> range(1, 10, length=101)
81+ 1.0:0.09:10.0
82+
83+ julia> range(1, 100, step=5)
84+ 1:5:96
7485```
7586"""
7687range (start; length:: Union{Integer,Nothing} = nothing , stop= nothing , step= nothing ) =
7788 _range (start, step, stop, length)
7889
90+ range (start, stop; length:: Union{Integer,Nothing} = nothing , step= nothing ) =
91+ _range2 (start, step, stop, length)
92+
93+ _range2 (start, :: Nothing , stop, :: Nothing ) =
94+ throw (ArgumentError (" At least one of `length` or `step` must be specified" ))
95+
96+ _range2 (start, step, stop, length) = _range (start, step, stop, length)
97+
7998# Range from start to stop: range(a, [step=s,] stop=b), no length
8099_range (start, step, stop, :: Nothing ) = (:)(start, step, stop)
81100_range (start, :: Nothing , stop, :: Nothing ) = (:)(start, stop)
0 commit comments