-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
range: Assume start=1 when not given. Use OneTo #39223
Conversation
I disagree with this as it adds one more caveat to the "three of start, step, stop, length, or two of start, stop, length" rule, and is not particularly useful syntax. I think it's actively good to leave this undefined in case some python people are tempted to use it instead of the more idiomatic 1:n. |
At first, I liked, the idea of writing |
I'm just going along with triage on the single positional argument: and @StefanKarpinski If we're going to have a single positional argument |
base/range.jl
Outdated
* Call `range` with any three of `start`, `step`, `stop`, `length`. | ||
* Call `range` with two of `start`, `stop`, `length`. In this case `step` will be assumed | ||
to be one. If both arguments are Integers, a [`UnitRange`](@ref) will be returned. | ||
* Call `range` with `step` and either `stop` or `length`. `start` will be assumed to be one. | ||
* Call `range` with one of `stop` or `length`. `start` and `step` will be assumed to be one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this accurate and succinct?
* Call `range` with any three of `start`, `step`, `stop`, `length`. | |
* Call `range` with two of `start`, `stop`, `length`. In this case `step` will be assumed | |
to be one. If both arguments are Integers, a [`UnitRange`](@ref) will be returned. | |
* Call `range` with `step` and either `stop` or `length`. `start` will be assumed to be one. | |
* Call `range` with one of `stop` or `length`. `start` and `step` will be assumed to be one. | |
* Call `range` with any three of `start`, `step`, `stop`, `length`. The omitted parameter is computed. | |
* Call `range` with fewer than three parameters, but including `stop` and/or `length`. If not provided, `start` and/or `step` are assumed to be one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is a good question. Can we simplify the documentation?
I'm wary of saying "The omitted parameter is computed" because someone may think additional processing occurs that may take time. In some cases, no additional computation is actually done unless the value of the parameter is actually requested. The preceding paragraph states "Mathematically a range is uniquely determined by any three of start
, step
, stop
and `length". That covers what needs to be said well. I would keep the first bullet point as is.
For the second bullet point,
If stop
and length
are specified, then only step
is assumed to be one. We could have assumed start
to be one, but that would have a distinct result. We at least need to say step
is assumed to be one first.
How about this:
- Call
range
with fewer than three parameters. Eitherstop
orlength
must be specified. If not provided,step
and/orstart
are assumed to be one in that order of precedence.
Oof, yeah. That means that In my mind, that's enough of an ambiguity to put a nail in this coffin. Sure, we can document an ordering to the defaults, but it feels quite arbitrary. (I should note that on triage we did discuss this form but only briefly — the focus was on the "improve range" PR.) |
I agree the ambiguity exists with I see a few options:
|
This pull request expands the valid input to
range
whenstart
can be assumed to be one and allows for a single positional argument to bestop
.Base.OneTo
is used if eitherstop
orlength
is provided as a single argument and are Integers.This pull request does not enable two or three positional argument syntax.