Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revised Range Documentation #34475

Merged
merged 4 commits into from
Jan 26, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions base/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,20 @@ Given a starting value, construct a range either by length or from `start` to `s
optionally with a given step (defaults to 1, a [`UnitRange`](@ref)).
One of `length` or `stop` is required. If `length`, `stop`, and `step` are all specified, they must agree.

If `length` and `stop` are provided and `step` is not, the step size will be computed
automatically such that there are `length` linearly spaced elements in the range (a [`LinRange`](@ref)).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me it would be clearer to keep the

the step size will be computed automatically such that there are length linearly spaced elements in the range

part because it's important and applies to everything. Then say something like

"""
...in a range. The returned type depends on the inputs, a [`StepRangeLen`](@ref) for floating-point inputs and [`LinRange`](@ref) otherwise.
"""

because that's effectively a detail that most people won't need to worry about. (Since the docs for StepRangeLen mention error-free arithmetic, I think we're covered as far as "purpose" goes.)

If numeric `length` and `stop` values are provided but `step` is not specified, the return value is
a [`StepRangeLen`](@ref) with a computed step. However, for non-numeric values of
`start` and `stop` (such as arrays), the `range` function instead returns a
[`LinRange`](@ref) object. (Both `StepRangeLen` and `LinRange` correspond
to equally spaced points up to roundoff errors, but deal with floating-point rounding
slightly differently.)

If `step` and `stop` are provided and `length` is not, the overall range length will be computed
timholy marked this conversation as resolved.
Show resolved Hide resolved
automatically such that the elements are `step` spaced (a [`StepRange`](@ref)).
# Example

```jldoctest
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]
```

`stop` may be specified as either a positional or keyword argument.

Expand Down