-
-
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
remove a[5:] syntax #4678
Comments
The problem is that |
What is |
I think that |
julia> dump(:(a[:9]))
Expr
head: Symbol ref
args: Array(Any,(2,))
1: Symbol a
2: QuoteNode
value: Int64 9
typ: Any
julia> dump(:(a[3:]))
Expr
head: Symbol ref
args: Array(Any,(2,))
1: Symbol a
2: Expr
head: Symbol :
args: Array(Any,(2,))
1: Int64 3
2: Symbol :
typ: Any
typ: Any |
I kind of agree with disallowing this. We would deprecate it first for a while and then remove the syntax altogether. |
I'd be ok with removing this, but it seems to be pretty popular (grepping through packages). Taking the "tail" of a vector or string is common, and being able to do it with 3 fewer characters is seductive. |
As in the original issue, |
Well, that's a fair point... get ready to see the deprecation warning for this every day for the next year :) |
I would love to see this get deprecated. |
We could disallow |
If you're disallowing :\d+, then you could just make it work as 1:n for a[:n], and error outside indexing context, like n: currently is. E.g.
|
One problem with allowing d=3
a[:d]=4 and wonder why they would get an error. |
As a general principle, we don't allow the context in which an expression occurs to affect its meaning. Making |
We could, but I prefer to let the set of available definitions correspond to what is actually possible, and not define everything just for convenience. For example |
Sure, that did feel a bit "off" to me too. |
So the basic plan is to just make |
Very good point about a[:d]. Then a[d:] working but a[:d] not is confusing indeed. You could make a[:d] work as expected, forcing the use of a[symbol("d")] in indexing context for the unlikely use of symbols, but that's sort of context-dependent. Amusingly, there is a context dependency in the "wrong" direction:
So in the case where ":end" might reasonably be a symbol it is a parse error, and in the case where it may not reasonably be symbol it is parsed as one :) EDIT: Ah, I was thinking of arrays only. For dictionaries, the use of symbol indexes is not unlikely at all, and at parsing time you won't know the difference. So illegalization seems like the only reasonable option. Still, the case with :end is a curious one. Even (:end) won't work, but a[:end] does. |
Yeah, |
This syntax was deprecated as a result of the discussion in JuliaLang/julia#4678.
Julia:
Python:
The text was updated successfully, but these errors were encountered: