-
-
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
Rename endof->lastindex and introduce firstindex. Fixes #23354 #25458
Conversation
src/julia-syntax.scm
Outdated
`(call (top endof) ,a) | ||
`(call (top size) ,a ,n)) | ||
`(call (top endindex) ,a) | ||
`(call (top last) (call (top axes) ,a ,n))) |
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.
I like this a lot, but could we incorporate this behavior into endindex
, too? That way the parser only lowers end
to endindex(A)
or endindex(A, n)
for the one- and n-arg cases, respectively.
Can we just keep |
or |
Keeping it If we implement If someone gets to the parsing portion of this soon, great. If not, perhaps it would make sense to merge with |
Note that the only part of this that would have to be done for 1.0 is the rename, which is part of why I tackled this. |
Here's a user's perspective:
I think
I don't think it ties in as nicely with |
Echoing Though Intuitiveness in direct use of |
One difficulty with parsing a[begin] is that some look ahead is required, since a[begin...end] is valid. Maybe if |
Maybe also preceded? e.g. |
When I had thought about doing this in the past, I was thinking we could just deprecate I really don't think we should try to support both |
@mbauman, yes, you are probably right. For example, |
What would happen if the interior of an indexing expression contains a macro call that expands to a begin/end block, and would cases like It feels like a very reasonable thing to just disallow |
Could we still rename |
|
@yurivish, we are discussing the parser, which affects only surface syntax. Macro expansion happens later, and wouldn't be affected. |
I rather like
|
I don't have much to add here at the moment, except to add that in #25261 I ran into a bunch of problems with code assuming that the iteration and indexing states where identical (e.g. using |
(The term |
I'm fine with any reasonable solution to the parsing issues. |
I think the best approach is probably to disallow |
I do prefer the names |
Needs a rebase. If the syntax part of this is controversial, maybe we can at least get the |
Actually I'll just go ahead, rebase this, and take out the syntax parts (hope you don't mind). |
Rebased. I backed out the |
doc/src/manual/interfaces.md
Outdated
@@ -161,7 +161,8 @@ julia> collect(Iterators.reverse(Squares(10)))' # transposed to save space | |||
|:-------------------- |:-------------------------------- | | |||
| `getindex(X, i)` | `X[i]`, indexed element access | | |||
| `setindex!(X, v, i)` | `X[i] = v`, indexed assignment | | |||
| `endof(X)` | The last index, used in `X[end]` | | |||
| `beginindex(X)` | The first index, used in `X[begin]` | |
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 syntax here is a holdover.
I find |
We could just call it |
... and |
Too bad they are exes. |
Rebased again. I'm planning to merge this one CI passes. |
Since |
I agree. It's not overly confusing for |
Rebased and renamed. |
You might want to amend the commit message for the first commit here since what it describes is no longer quite what it does, since the names are different. |
Done |
NEWS.md
Outdated
@@ -991,6 +991,8 @@ Deprecated or removed | |||
|
|||
* `Base.@gc_preserve` has been deprecated in favor of `GC.@preserve` ([#25616]). | |||
|
|||
* `endof(a)` has been renamed `endindex(a)` ([#23554]). |
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.
lastindex
cb6fd0e
to
c6de074
Compare
Some idiot merged something that conflicts with this. I'll rebase again, sigh. Planning to merge next time we're green on CI. |
It was decided to delay this syntax change until after 1.0, since it is non-breaking. Once somebody wants to take this up again, they can simply revert this commit.
People expressed concern about the phrasing, so for the record, it was me in #25733, I'm the idiot ;). |
Thanks for picking this up and pushing it over the line, @Keno; it's been a busy few weeks. |
While working on JuliaLang/Juleps#47 I noticed that we really should have
beginindex
(see #23354). This almost resolves that issue: I think I have all the tedious stuff done, but my lisp is laughable and character-twiddling was insufficient to fix the parsing ofa[begin]
. Would love some help. @stevengj? (Anyone who wishes, you are more than welcome to push directly to this branch, or do whatever you find most convenient.)I defined specific
beginindex
methods for every type that defines what is now calledendindex
(formerlyendof
). Sincebeginindex
is a new function, I also added a "deprecation" that returns 1 for any object, as a way of encouraging package authors to define it as needed. Hope this seems like a reasonable strategy.