julia> struct Polynomial{R}
coeffs::Vector{R}
end
julia> function (p::Polynomial)(x)
v = p.coeffs[end]
for i = (length(p.coeffs)-1):-1:1
v = v*x + p.coeffs[i]
end
return v
end
julia> (p::Polynomial)() = p(5)
I expected it to work, so I could for example call p(3), instead I get an error "Multiple definitions for Polynomial".
Functors needs to currently be defined in the same cell as the type (struct Polynomial{R} in your case). See https://github.com/fonsp/Pluto.jl/issues/2038 which tracks the issue and has more context.
Video link: https://share.vidyard.com/watch/156vhpJQCmXUcbUbzm5QWq? Notebook Gist: https://gist.github.com/ggggggggg/08a49b61756565a1321b6f0df79d122f
I tried to define a functor following the julia docs here: https://docs.julialang.org/en/v1/manual/methods/#Function-like-objects-1 Here is the full text of the example I tried to recreate:
I expected it to work, so I could for example call
p(3)
, instead I get an error "Multiple definitions for Polynomial".