Why can't this:
function functionWithPaths(state::State, a::Int, b::Int, onPathA)
if( a > b)
onPathA(a, b)
state.value = a
else
state.value = a + b
end
end
function test()
array = zeros(Int, 100)
onPathA(a, b) = array[a] = b
functionWithPaths(State(0), 10, 20, onPathA)
end
Be unrolled to this:
function unrolled_functionWithPaths(state::State, a::Int, b::Int, array) #
`array` injected
if( a > b)
array[a] = b # Injected function
state.value = a
else
state.value = a + b
end
end
I tried to keep it simple here - this is not the exact use case, but it is
exactly what I want.
However, I tried using anonymous functions, both Julia's and FastAnonymous'
, and they both have issues in my more complex use case.
The best route, as far as I can tell, is to create a macro. I tried a few
ways and got stuck.
Maybe someone can create it with less effort? I have the feeling this
would be *very* useful.