support a[begin] for a[firstindex(a)] - #33946
Conversation
|
I think it's really unfortunate not to be able to use |
It's been deprecated for a while now and I haven't seen any complaints? You can always use
The basic motivation here is to fix the asymmetry with |
|
(Windows CI failures look unrelated. One is a download failure and another is something with backtraces.) |
|
@JeffBezanson, it seems like if we're not going to do this, then we should introduce an alternative syntax for this, such as the |
|
I remember we spent quite a while discussing syntax for this in the 1.0 timeframe, and unfortunately nobody was able to come up with anything appealing. Personally I do prefer |
|
That discussion was at #15750? Given that we already have |
|
Notes from triage. @JeffBezanson is against continuing to disallow julia> var"end" = 1
1
julia> :(a[$end])
:(a[1])
julia> var"begin" = 1
1
julia> :($begin)
1
julia> :(a[$begin])
:(a[1])However, those usages are so weird that breaking them in a minor release would be fine. We're also fortunate that this does not work: julia> :($begin 1 end)
ERROR: syntax: missing comma or ) in argument list
Stacktrace:
[1] top-level scope at REPL[13]:0Therefore using However, @vtjnash and I were ok with just merging this and making |
|
Another +1 to merging this and going ahead with |
|
I think this may need to include an update to |
|
I suspect that deprecating And anyway, given that we are not going to get rid of |
|
Yes, I think we should just go for it. We already did the painful part: deprecating |
(Not too painful in practice. Did anyone even notice that this happened? I don't recall it ever being mentioned, and there are no links to #25614 on github or discourse. More evidence that this usage is not significant, compared to the ubiquitous need for indexing from the beginning and ending of arrays.) |
As far as I can tell, expression printing looks fine, including keyword cases ala #34038. For example julia> :(a[begin:end, begin+1, end-1] + f(foo[begin]; kw=bar[begin+2]))
:(a[begin:end, begin + 1, end - 1] + f(foo[begin]; kw=bar[begin + 2]))Is there a specific case you are concerned about? (The |
I believe that @JeffBezanson fixed a number of instances of people doing this in packages for 1.0. |
Hm, probably should. Outside of julia> Base.remove_linenums!(:(a[$:begin, $:end, ($:begin; $:end;)]))
:(a[begin, end, begin
begin
end
end]) |
I hit a few, too. IIRC the cases where this cropped up were almost entirely typed comprehensions. |
|
@vtjnash, I see… Inside indexing expressions, blocks should probably print as I feel like the printing of julia> :($:for + 1)
:(for + 1) |
@vtjnash, this should be fixed now. julia> Base.remove_linenums!(:(a[$:begin, $:end, ($:begin; $:end;)]))
:(a[begin, end, (begin;
end)]) |
|
|
|
@maleadt, note that this is just syntactic sugar (aside from changes to |
|
Win32 test failure is: Linux64 failure is: Both seem unrelated? |
The tests run are not benchmarks. It is running the tests of all registered packages on master vs this branch. |
See #34075 |
|
Triage: will merge this. |
|
Before I replicate in CSTParser, is the following intended? Meta.parse("x[end 1]") # OK
Meta.parse("x[1 end]") # not OK |
|
That looks like a bug to me. |
* Revert "Back out `a[begin]` syntax" This reverts commit e016f11. * rm deprecation for a[begin...] * fix parsing of begin in [...] * fix printing of blocks inside indexing expressions
| (if (null? tuples) | ||
| (if (and last (= n 1)) | ||
| `(call (top firstindex) ,a) | ||
| `(call (top first) (call (top axes) ,a ,n))) |
There was a problem hiding this comment.
I missed this, but it's a bit of a shame that this isn't firstindex(a, n) to mirror lastindex(a, n).
There was a problem hiding this comment.
Sounds like a good non-breaking PR?
This is resurrected from #25458, and reverts commit e016f11. Since the use of
begininside indexing expressions was deprecated in Julia 0.7 (#25614), this is not a breaking change. Resolves #15750.cc @Keno, @timholy