Open
Description
Over at JuliaLang/julia#46364 @eschnett observed
The array expression
[begin 1 end]
creates a 1-element array. Thebegin
...end
block is not really necessary here, but can be convenient if the expression is much more complicated, e.g. a comprehension.The typed array expression
Int[begin 1 end]
leads to the parsing errorERROR: syntax: unexpected "end"
.
This being due to the ambiguity of whether begin
or end
in the first slot inside a[]
should be treated as block keywords or as the first/last indices of the array:
julia> dump(:(a[end 1]))
Expr
head: Symbol typed_hcat
args: Array{Any}((3,))
1: Symbol a
2: Symbol end
3: Int64 1
julia> dump(:(a[1 end]))
ERROR: syntax: unexpected "end"
Stacktrace:
[1] top-level scope
@ none:1
Over in that issue, it was suggested that the parser could explain the issue and suggest using let
instead of begin
, which seems like a good option.
See also: #81