using GLMakie, Makie
rng = Observable(range(-10,10,1000))
f = Observable((x)->sin(x))
g = Observable((x)->x)
dep = @lift(Point2f.([($g(i), $f(i)) for i in $rng]))
rng[] = range(-10,5,1000)
f[] = (x) -> x^2
Changing rng works fine but not f.
What is the syntax for changing an observable function to a different function?
Therefore, you cannot change an Observable generated for one function to another function, because when you create an Observable it is, by default, done for a specific type. (you can find out by: ?Observable in the REPL).
So, you need to create Observables for your functions that are “wide enough” (in terms of types they accept).
The following works:
using GLMakie, Makie
rng = Observable(range(-10,10,1000))
f = Observable{Function}((x)->sin(x))
g = Observable{Function}((x)->x)
dep = @lift(Point2f.([($g(i), $f(i)) for i in $rng]))
rng[] = range(-10,5,1000)
f[] = (x) -> x^2
I guess that you are not running your plotting code in “must-have-highest-performance” setting, so it’s probably fine to have the abstractly typed Observables around…