On Sun, Jan 24, 2016 at 7:57 PM, Bryan Rivera <[email protected]> wrote:
> 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.
>

You can do this with a functor (callable types), which I think someone
have already showed you how to do in reply to one of your previous
post.
Plain closures should be able to be inlined once Jeff's closure rewrite
is merged.

Reply via email to