I am experimenting with named tuples to store my parameters for code readability. I have noticed that although one can create a tuple with one element, it cannot be accessed via the dot notation:
a = (b=3)
returns
julia> a.b
ERROR: type Int64 has no field b
Stacktrace:
[1] getproperty(::Int64, ::Symbol) at ./Base.jl:33
On the other hand, a tuple with two elements:
a = (b=3, c=4)
handles perfectly fine:
a.b
returns 3 as expected.
Is this expected behavior? What is the rationale? In general, I might wish to store parameters in a named tuple (perhaps a named array in the future), and at times, there might only be a single parameter.
I was taught (in Python, but it applies here too) to think of the comma as the tuple operator, not the parentheses. I’ve found that lesson helpful in cases like this.