function f(x)
if true
g = x -> 2x
else
g = x -> 3x
end
g(x)
end
My understanding is that doing either function f end or f(args...) = #code creates a function f in the namespace of the current module. However anonymous functions (“lambdas”) are not like this.
Note that you could do
@static if true
g(x) = 2x
else
g(x) = 3x
end
in the global scope of the module and it should work fine (in fact, you probably don’t even need the @static if you do it in global scope).
That makes sense. I know that the REPL does various things to cut down on compile time (or perhaps just to silence warnings?), but I don’t know the details.