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

Add range(start, stop, length) #39055

Closed
wants to merge 2 commits into from

Conversation

mkitti
Copy link
Contributor

@mkitti mkitti commented Dec 31, 2020

This is a minimal implementation of range(start, stop, length) with no fuss. It adds the three positional argument version. One or two positional arguments are still disallowed.

Closes #38750

# The one line of actual code added is literally the one line below
julia> Base.range(start, stop, length::Union{Integer,Nothing}) = Base._range(start, nothing, stop, length)

julia> range(1,5,5)
1.0:1.0:5.0

julia> range(1,5,2)
1.0:4.0:5.0

julia> range(1,5)
ERROR: ArgumentError: At least one of `length` or `step` must be specified
Stacktrace:
 [1] _range2(::Int64, ::Nothing, ::Int64, ::Nothing) at .\range.jl:97
 [2] range(::Int64, ::Int64; length::Nothing, step::Nothing) at .\range.jl:94
 [3] range(::Int64, ::Int64) at .\range.jl:94
 [4] top-level scope at REPL[4]:1
 
 julia> range(5)
ERROR: ArgumentError: At least one of `length` or `stop` must be specified
Stacktrace:
 [1] _range(::Int64, ::Nothing, ::Nothing, ::Nothing) at .\range.jl:126
 [2] range(::Int64; length::Nothing, stop::Nothing, step::Nothing) at .\range.jl:91
 [3] range(::Int64) at .\range.jl:91
 [4] top-level scope at REPL[5]:1

While I still think we should evaluate the larger picture, there are compatible alternatives I would like to explore such as using Pair to represent start => stop, resulting in unambiguous syntax. My approach to that depends on if this is integrated or not.

@mkitti
Copy link
Contributor Author

mkitti commented Dec 31, 2020

See 👍🏻 in #38750 (comment) by @StefanKarpinski

@mkitti
Copy link
Contributor Author

mkitti commented Jan 8, 2021

Closing for now with deference to comments in #38750 and #38041. I can rebase later if issues are still not resolved.

@mkitti mkitti closed this Jan 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

range(start, stop, length)
1 participant