@@ -46,7 +46,7 @@ function _colon(start::T, step, stop::T) where T
46
46
end
47
47
48
48
"""
49
- range(start; length, stop, step=1)
49
+ range(start[, stop] ; length, stop, step=1)
50
50
51
51
Given a starting value, construct a range either by length or from `start` to `stop`,
52
52
optionally 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
58
58
If `step` and `stop` are provided and `length` is not, the overall range length will be computed
59
59
automatically such that the elements are `step` spaced (a [`StepRange`](@ref)).
60
60
61
+ `stop` may be specified as either a positional or keyword argument.
62
+
61
63
# Examples
62
64
```jldoctest
63
65
julia> range(1, length=100)
@@ -71,11 +73,25 @@ julia> range(1, step=5, length=100)
71
73
72
74
julia> range(1, step=5, stop=100)
73
75
1:5:96
76
+
77
+ julia> range(1, 10, length=101)
78
+ 1.0:0.09:10.0
79
+
80
+ julia> range(1, 100, step=5)
81
+ 1:5:96
74
82
```
75
83
"""
76
84
range (start; length:: Union{Integer,Nothing} = nothing , stop= nothing , step= nothing ) =
77
85
_range (start, step, stop, length)
78
86
87
+ range (start, stop; length:: Union{Integer,Nothing} = nothing , step= nothing ) =
88
+ _range2 (start, step, stop, length)
89
+
90
+ _range2 (start, :: Nothing , stop, :: Nothing ) =
91
+ throw (ArgumentError (" At least one of `length` or `step` must be specified" ))
92
+
93
+ _range2 (start, step, stop, length) = _range (start, step, stop, length)
94
+
79
95
# Range from start to stop: range(a, [step=s,] stop=b), no length
80
96
_range (start, step, stop, :: Nothing ) = (:)(start, step, stop)
81
97
_range (start, :: Nothing , stop, :: Nothing ) = (:)(start, stop)
0 commit comments