Append struct element to an array

Hello,
I am a newbie programmer in Julia, and I can not explain a bizarre behavior of the append command.
I have a structure define as

struct Point{T}
  x::T
  y::T
  z::T
end 

and an array of points:

points = [Point{Float64}(rand(),rand(),rand()) for i = 1:100]

if I create another point:

p = Point{Float64}(1.0, 1.0, 1.0)

Why I can not append it to the points array?

julia> append!(points,p)
ERROR: MethodError: no method matching length(::Point{Float64})
Closest candidates are:
  length(::Core.SimpleVector) at essentials.jl:582
  length(::Base.MethodList) at reflection.jl:732
  length(::Core.MethodTable) at reflection.jl:806
  ...
Stacktrace:
 [1] _append!(::Array{Point{Float64},1}, ::Base.HasLength, ::Point{Float64}) at ./array.jl:908
 [2] append!(::Array{Point{Float64},1}, ::Point{Float64}) at ./array.jl:902
 [3] top-level scope at none:0

You want push! to add just a single element to the end of an array. append! tries to add an array of many elements.

3 Likes