Skip to content

Instantly share code, notes, and snippets.

@ggggggggg
Created December 4, 2023 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ggggggggg/08a49b61756565a1321b6f0df79d122f to your computer and use it in GitHub Desktop.
Save ggggggggg/08a49b61756565a1321b6f0df79d122f to your computer and use it in GitHub Desktop.
pluto functor bug
### A Pluto.jl notebook ###
# v0.19.32
using Markdown
using InteractiveUtils
# ╔═╡ a353c1f3-0921-4c9b-ab1d-a34cb262b3d9
# following docs at https://docs.julialang.org/en/v1/manual/methods/#Function-like-objects-1
# lets make a functor
# ╔═╡ 9de6d141-a55f-4c65-a326-27485dedb0c2
p(5)
# ╔═╡ 75220770-92be-11ee-2bf9-61e84388414e
struct Polynomial{R}
coeffs::Vector{R}
end
# ╔═╡ 2c3218fa-bd79-4c14-864b-3c3b2b4bc7ea
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
# ╔═╡ Cell order:
# ╠═a353c1f3-0921-4c9b-ab1d-a34cb262b3d9
# ╠═75220770-92be-11ee-2bf9-61e84388414e
# ╠═2c3218fa-bd79-4c14-864b-3c3b2b4bc7ea
# ╠═9de6d141-a55f-4c65-a326-27485dedb0c2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment