I doubt it, but maybe there are macros for this. It seems unlikely, since a dynamic type like you propose would not allow the type to be compiled ahead of time for dispatch.
In general, you need to define the types (struct
s) explicitly first. Then create variables as instances of those types.
julia> myinfo = PInfo("Hello", 2, "John", "Snow")
PInfo("Hello", 2, "John", "Snow")
julia> typeof(myinfo)
PInfo
No, again the allocation will occur once the type is invoked not in the definition of the type.
Define a simple type Test
:
struct Test
v::Vector{Int64}
end
It is possible to create an undef
instance as you propose, but it is verbose and the data will be junk (not necessarily zeros):
julia> t = Test(Vector{Int64}(undef, 4))
Test([0, 0, 0, 0])
I would probably just:
julia> t = Test(zeros(4))
Test([0, 0, 0, 0])
Then, either way, you can start filling the values.
julia> t.v[3] = 5
5
julia> t
Test([0, 0, 5, 0])