I may be missing the point here, but wouldn't it be easier to define sumf 
as a macro?

macro sumf(f, xs)
  quote
    s = 0.0
    x = $(esc(xs))
    for i = 1:length(x)
      s += $(esc(f))(x[i])
    end
    s
  end
end

@sumf(sinc_plus_x, x)

This is just as fast and has the advantage that it will work when f is only 
in the local scope.


On Saturday, 17 May 2014 11:50:56 UTC+1, Tim Holy wrote:
>
> On Friday, May 16, 2014 02:36:03 PM [email protected] <javascript:>wrote: 
> > - The solver need to be fast and for that, inlining is of paramount 
> > importance. I know that there is no way to inline F for the time being. 
> Do 
> > we expect inlining on function argument in the near future of Julia ? 
>
> I can't speak for when this will happen in a "nice" way, but using Julia's 
> metaprogramming capabilities there is a (somewhat ugly) way to get what 
> you 
> want. Since I'm planning to use this trick myself shortly, I created a 
> little 
> demonstration: 
>
> https://gist.github.com/timholy/bdcee95f9b7725214d8b 
>
> If you prefer, you don't have to separate out the definition of the body 
> from 
> the eval(quote...end) part, I just did it that way to better illustrate 
> the 
> separate ideas. 
>
> --Tim 
>
>

Reply via email to