Reputation: 1207
In Julia it is possible to have public fields in functions for instance
function foo(arg)
global a = arg
a
end
Is it possible to achieve something similar using Julia structures. For instance what I would like to do is:
julia> struct foobarfoo
global a
end
julia>
julia> test = foobarfoo(1)
ERROR: MethodError: no method matching foobarfoo(::Int64)
Stacktrace:
[1] top-level scope at none:0
julia> a
ERROR: UndefVarError: a not defined
Instead of:
julia> struct foobarfoo
a
end
julia> test = foobarfoo(1)
foobarfoo(1)
julia> test.a
1
julia>
Upvotes: 0
Views: 97
Reputation: 724
I think that the short answer is no but you may be able to achieve what you want using the @unpack
macro of Parameters.jl.
Upvotes: 2