You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Generally, NamedTuples support the interfaces of both structs and tuples. But neither structs nor tuples support indexing by symbol. It may be convenient for situations with a non-identifier property name, but it mixes the semantics of getproperty and getindex confusingly by dispatching on the argument type.
getproperty should not decide its semantics based on the type of the argument --- for different behavior, use a different function. Imho, getindex(::NamedTuple, i) should index positions and getproperty should go by property name. These should be kept separate.
The text was updated successfully, but these errors were encountered:
The major drawback of this is that getindex has much better syntax for using NamedTuple for practical tasks when the key is a variable: my_nt[k] vs getproperty(my_nt, k). I agree with most of #49932 but there is no reason we cant change eachindex and keep getindex - Int also works in getindex.
Generally, NamedTuples support the interfaces of both structs and tuples. But neither structs nor tuples support indexing by symbol. It may be convenient for situations with a non-identifier property name, but it mixes the semantics of
getproperty
andgetindex
confusingly by dispatching on the argument type.getproperty
should not decide its semantics based on the type of the argument --- for different behavior, use a different function. Imho,getindex(::NamedTuple, i)
should index positions andgetproperty
should go by property name. These should be kept separate.The text was updated successfully, but these errors were encountered: