I wanted to use “end” as a key of NamedTuple, however:
julia> (start = 1, end = 2)
ERROR: syntax: unexpected "end"
While I understand “end” is a reserved keyword, I guess there is no ambiguity if it is inside parentheses so we may parse it correctly.
My current workaround is:
julia> NamedTuple{Tuple([:start, :end])}([1,2]).end
2
which is a little bit ugly.
Another case is to use “end” as a struct field, the workaround would be even more ugly:
struct Range
start
end_
end
function Base.getproperty(x::Range, symbol::Symbol)
if symbol === :end
getfield(x, :end_)
else
getfield(x, symbol)
end
end
I am not sure about the struct field case, but I feel using arbitrary key for a named tuple would be a valid usage. Any opinions?