consider the following code:
function foo(x::Int; d=:out) myfn = (d == :out) ? fn1 : fn2 z = 0 for i = 1:x z += myfn(i) end end
I understand the inefficiency that results from the compiler not being able to tell that
myfn won’t change within the loop. Is there a way to do this efficiently that preserves the simplicity of the function? I tried wrapping the loop inside a
let myfn = (d == :out) ? fn1 : fn2 block but that didn’t show any benchmarking improvements.