-
-
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
allow range(start, stop; ...)
#28708
Conversation
Yes please add that and slip it into 1.0.1. The stop thing really was a little odd when I ported Winston to 1.0. |
Should be v1.1. |
Let's not commit a flagrant violation of SemVer in literally our first post-1.0 release. @JeffBezanson, this is why I suggested that a fairly quick 1.1 on the order of 1-2 months might be in order because there are a number of little features like this that were unblocked by the removal of deprecations and which were not implemented yet in 1.0 on account of the accelerated time frame of the release. |
base/range.jl
Outdated
@@ -76,6 +76,34 @@ julia> range(1, step=5, stop=100) | |||
range(start; length::Union{Integer,Nothing}=nothing, stop=nothing, step=nothing) = |
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.
Maybe remove the docstring from this method? Or simplify it significantly? The two are essentially identical and will just end up looking repetitive in the docs.
Is this PR (or an equivalent interface) almost certainly going into the v1.1 release? To the extent that it can be discussed wither |
Any chance of including |
That one I never liked in matlab, personally. I think the worry with the new range is that my guess on the default behavior (if any) is that |
Why in the world is the default length 50?! Why not 100? That seems like a better and less surprising default. Defaulting to 50 is just something someone liked once upon a time that has now become enshrined for no reason whatsoever in various systems that copied each other. Let’s break the cycle of an arbitrary default value that never made any sense in the first place. |
@StefanKarpinski is this new interface sufficiently baked into Julia plans that we can try to make a case that it can go into This was a strategy brought up by @simonbyrne (though I want to be clear that he didn't endorse it necessarily). The idea is that if the new range interface is finalized, that we would add it to Compat.jl so that people appalled by the current range interface can opt-in with the Compat.jl interface, at which point it would eventually just smoothly transition to v1.1 And with no semver violations, or conflicting homegrown type piracy between code bases to get the new interface. |
Once it's in Base, I see no reason it couldn't be added to Compat. |
I don't particularly care about the exact default length, but it's not completely arbitrary: 50 points are enough to capture the behavior of most smooth functions for plotting purposes, and "Break the tyranny of the sensible default value!" isn't an actual argument against default values. But this is a distracting bikeshed, and the PR's already an improvement over the current syntax, so I'll shut up. |
Pre-Compating this seems reasonable. There’s no real debate about what we’re going to do here. |
@StefanKarpinski Does this need to be merged before we can add it to |
@StefanKarpinski, well, this leads to the proposal: let's make 100 as default. One possible justification for this choice is that the currently Besides defaulting to TL;DR: choosing the least useful option as default one does not seem reasonable to me. |
I don't think a default step of 1 is as random as a default length of 100 or 50. Consecutive integers aren't exactly some crazy thing we just made up. I guess it's slightly arbitrary when the arguments are not integer-valued though. |
@JeffBezanson Yes, it can be quite difficult to recognize when seeing in someone's code something like I guess my point is that the current default has also arbitrary choices baked into it that make it confusing when reading someone's code. Furthermore, it is already covered by more slicker |
Is a default for |
A default step of 1 clearly makes sense for We could also require that a |
The most conservative choice is to require one of them to be passed. That seems fine for now. |
I'd still prefer to require either |
AV error looks unrelated but interesting. |
Ah, I wasn't even aware we supported |
540f547
to
da3f77d
Compare
Comments addressed. |
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.
The docstring gives the default step=1
which is not entirely correct. I'm not sure it's worth documenting the different behavior of the one-arg and two-arg versions. Maybe we restrict the documentation to the behavior of the two-arg version (either step
or length
has to be specified) and only silently keep supporting the old one-arg-with-neither-given?
base/range.jl
Outdated
@@ -71,11 +73,28 @@ julia> range(1, step=5, length=100) | |||
|
|||
julia> range(1, step=5, stop=100) | |||
1:5:96 | |||
|
|||
julia> range(1, 100) | |||
1:100 |
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.
This doctest fails with the latest changes.
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.
Oops.
da3f77d
to
a1700c0
Compare
Aha: the reason the default step of |
finishes #25896
a1700c0
to
9704320
Compare
Ah, yes. Although that means the default is not really 1: julia> range(1, stop=5)
1:5
julia> range(1, stop=5, step=1)
1:1:5 I'd expect giving the default explicitly not making any difference at all. Irrespective of the |
I guess we could change the documentation to say the default is a I don't think |
changes between Julia 1.0 and 1.1, including: - Custom .css-style for compat admonitions. - Information about compat annotations to CONTRIBUTING.md. - NEWS.md entry for PRs #30090, #30035, #30022, #29978, #29969, #29858, #29845, #29754, #29638, #29636, #29615, #29600, #29506, #29469, #29316, #29259, #29178, #29153, #29033, #28902, #28761, #28745, #28708, #28696, #29997, #28790, #29092, #29108, #29782 - Compat annotation for PRs #30090, #30013, #29978, #29890, #29858, #29827, #29754, #29679, #29636, #29623, #29600, #29440, #29316, #29259, #29178, #29157, #29153, #29033, #28902, #28878, #28761, #28708, #28156, #29733, #29670, #29997, #28790, #29092, #29108, #29782, #25278 - Documentation for broadcasting CartesianIndices (#30230). - Documentation for Base.julia_cmd(). - Documentation for colon constructor of CartesianIndices (#29440). - Documentation for ^(::Matrix, ::Number) and ^(::Number, ::Matrix). - Run NEWS-update.jl. Co-authored-by: Morten Piibeleht <morten.piibeleht@gmail.com> Co-authored-by: Fredrik Ekre <ekrefredrik@gmail.com>
changes between Julia 1.0 and 1.1, including: - Custom .css-style for compat admonitions. - Information about compat annotations to CONTRIBUTING.md. - NEWS.md entry for PRs #30090, #30035, #30022, #29978, #29969, #29858, #29845, #29754, #29638, #29636, #29615, #29600, #29506, #29469, #29316, #29259, #29178, #29153, #29033, #28902, #28761, #28745, #28708, #28696, #29997, #28790, #29092, #29108, #29782 - Compat annotation for PRs #30090, #30013, #29978, #29890, #29858, #29827, #29754, #29679, #29636, #29623, #29600, #29440, #29316, #29259, #29178, #29157, #29153, #29033, #28902, #28878, #28761, #28708, #28156, #29733, #29670, #29997, #28790, #29092, #29108, #29782, #25278 - Documentation for broadcasting CartesianIndices (#30230). - Documentation for Base.julia_cmd(). - Documentation for colon constructor of CartesianIndices (#29440). - Documentation for ^(::Matrix, ::Number) and ^(::Number, ::Matrix). - Run NEWS-update.jl. Co-authored-by: Morten Piibeleht <morten.piibeleht@gmail.com> Co-authored-by: Fredrik Ekre <ekrefredrik@gmail.com>
Addition of NEWS and compat admonitions for important changes between Julia 1.0 and 1.1, including: - Custom .css-style for compat admonitions. - Information about compat annotations to CONTRIBUTING.md. - NEWS.md entry for PRs #30090, #30035, #30022, #29978, #29969, #29858, #29845, #29754, #29638, #29636, #29615, #29600, #29506, #29469, #29316, #29259, #29178, #29153, #29033, #28902, #28761, #28745, #28708, #28696, #29997, #28790, #29092, #29108, #29782 - Compat annotation for PRs #30090, #30013, #29978, #29890, #29858, #29827, #29754, #29679, #29636, #29623, #29600, #29440, #29316, #29259, #29178, #29157, #29153, #29033, #28902, #28878, #28761, #28708, #28156, #29733, #29670, #29997, #28790, #29092, #29108, #29782, #25278 - Documentation for broadcasting CartesianIndices (#30230). - Documentation for Base.julia_cmd(). - Documentation for colon constructor of CartesianIndices (#29440). - Documentation for ^(::Matrix, ::Number) and ^(::Number, ::Matrix). - Run NEWS-update.jl. Co-authored-by: Morten Piibeleht <morten.piibeleht@gmail.com> Co-authored-by: Fredrik Ekre <ekrefredrik@gmail.com>
This was discussed in #25896, and can be added now that deprecations are removed. This probably could have been in 1.0, and so might be ok to put in a point release. Thoughts? Otherwise it can go in 1.1.