Append an array inside a function

No it has appened 5 4s:

julia> SV = rand(10);

julia> function add_star(SV)
           for i = 1:5
               append!(SV, 4)
           end
           return SV
       end
add_star (generic function with 1 method)

julia> add_star(SV);

julia> SV
15-element Array{Float64,1}:
 0.7833650176317701
 0.5668846033320463
 0.4391438535780501
 0.1708544616711889
 0.5183882750256887
 0.039540666370839306
 0.9220275850039967
 0.2936365813778392
 0.6266212769148911
 0.7356570139131633
 4.0
 4.0
 4.0
 4.0
 4.0

Note though, for single element additions you should use push! instead of append!.

4 Likes