It seems we have to use reflections in order to overwrite a function from an outer scope.
Please look at the following minimal example
module MyModule f(a) = a function f2() h = getfield(MyModule, :f) #= if you uncomment the following you get an `ERROR: UndefVarError: f not defined` pointing to exactly this assignment `h = f` =# # h = f # PLEASE UNCOMMENT THIS f(args...; kwargs...) = h(2, args...; kwargs...) f() end end MyModule.f2() # 2
If we know the outer scope is just module, we can use simple
getfield(MyModule, :myfunc) to refer to the function which we want to overwrite locally (as used in the example), however if you have nested functions I even don’t know a way to do that.
Is this restriction needed? or could julia just correctly infer that the first
h = f is pointing correctly to the outer scope?
I am using julia 1.1