I am new to Julia. I am trying to initialize an array of functions, and add a function to it.
This is my code:
arr = Array{Function, 1}
push!(arr, sin)
And this is the error I’m getting
MethodError: no method matching push!(::Type{Array{Function,1}}, ::typeof(sin))
Closest candidates are:
push!(::Any, ::Any, !Matched::Any) at abstractarray.jl:2095
push!(::Any, ::Any, !Matched::Any, !Matched::Any...) at abstractarray.jl:2096
push!(!Matched::Array{Any,1}, ::Any) at array.jl:860
...
What is my problem?
I also tried this version according to the documentation
arr2 = Array{Function}(undef, 1)
push!(arr2, sin)
but then arr2
is
2-element Array{Function,1}:
#undef
sin
and I cannot access the function. When I execute arr2[1]
I get
UndefRefError: access to undefined reference
I do not understand why I get this behavior. I would love to some explanation.