Because I want to match an existing naming convention I do not have the freedom to choose whatever struct field names I’d like.
Is there any to create structs with fields that are reserved Julia keywords? I think it should be possible, after all something like the following syntax should not be confusing:
Here’s an alternative approach, which is more verbose, but perhaps more familiar-looking:
struct Test
_local::Float64
end
function Base.getproperty(t::Test, sym::Symbol)
if sym == :local
return t._local
else
return getfield(t, sym)
end
end
jl> t = Test(1.2)
Test(1.2)
jl> t.local
1.2
Mandating particular field names is questionable practice though, and the names shouldn’t really be part of an interface. Why is this done? Accessor functions are normally preferred.
Excellent! Thank you for pointing me to the var keyword. That works beautifully for my application.
I’ll also think about developing accessor functions, but it is handy/easier to keep the same field names that were used in the original data structure that I am replicating in Julia.