I have a struct as follows:
@kwdef struct Node
index
value
optional_attribute = 0.0
end
@kwdef struct Network
nodes::Vector{node} = Node[]
end
Now, I can define a Network object and assign nodes to it. However, I want to do it a bit differently using macros. Something like:
#Initialize a network
V = Network()
#Now fill in the nodes using macro
@node(V, 1, 10) #index=1, value=2
@node(V, 2, 20, optional_attribute=5)
#and so on
How do I define this macro @node. Also, since node belongs to V, I should be later able to retrieve it using V.nodes. This is probably a trivial question but I have never used macros before hence the question. Any help is appreciated. Thank you.