1. You can trivially write a `getproperty` method for a tuple. It is considered to be type piracy and thus runs the risk of colliding with someone else's definition, but the language absolutely lets you do it.
2. You can broadcast over the fields of a `NamedTuple` by defining appropriate methods. Again, it's type piracy, so take that into consideration, but the language lets you do this easily as well.
3. The https://github.com/JuliaArrays/PaddedViews.jl package implements exactly what you're saying Julia won't let you do.
If anything, Julia errs on the side of allowing you to do too many things! There are very few things the language really won't let you do.
julia> (x = 1, y = 2) .+ (x = 1, y = 2)
ERROR: ArgumentError: broadcasting over dictionaries and `NamedTuple`s is reservedDo you also expect your 'custom getproperty' (whatever it might do) to have been predicted and pre-implemented by someone else? And do you also expect arrays to 'just know' what value or behaviour you are looking for whenever you index out of bounds?
julia> Base.broadcasted(f, x::NamedTuple, y::NamedTuple) = "my custom method!"
julia> (x=1, y=2) .+ (x=1, y=2)
"my custom method!" julia> function Base.getproperty(x::Tuple, f::Symbol)
if f == :a
return x[1]
elseif f == :b
return x[2]
else
return x[3]
end
end
julia> (3,4,5).a
3
Edit: Okay, why am I getting randomly downvoted here?There may be other packages or methods for doing the other things you want. I’d think that broadcasting over a NamedTuple would iterate over the key => value pairs, but I haven’t tried it.
However, I keep running into niggling corner cases that kind of make Julia's promise of a powerful, extensible, yet intuitive type system less convincing.
ME: I want to write a custom getproperty() for Tuple!
JULIA: No.
ME: I want to broadcast over the fields of a NamedTuple!
JULIA: Not allowed.
ME: I want to get a view, not copy, with `@view M[m:n, r:s]`, but also get the ability to specify a default for out-of-range indices, like `get()` allows.
JULIA: I'm afraid I can't let you do that.