Appending an element to an array in Julia works like this:
v = Array{Int32, 1}(0)
append!(v, 1)
append!(v, 2)
println(v) # prints: Int32[1,2]
When I try this with a custom type
type Node
label::String
value::Int32
end
nodes = Array{Node, 1}(0)
append!(nodes, Node("a", 42))
I get the following error:
ERROR: LoadError: MethodError: no method matching length(::Node)
I assume I have to 'implement' the length
method but do not know how.
Try this
then you get
you've got to explicitly create a function for this particular type as
append!
or any of theBase
functions sometimes (or perhaps always I havent checked) wont acceptAny
The
append!
command doesn't do what you think it does. You're thinking of thepush!
command.The
append!
command appends two arrays together. Both arguments need to be arrays:No
length
implementing necessary(that error was just telling you it tried to read the length of your array for the second argument and found something that was not an array.)