When I try this, I get an error: ERROR: type: test2: in apply, expected Function, got CFunction{Float64,Float64}
It looks like "call" doesn't exist in version 0.3. I suppose I need 0.4 to make this work. It doesn't appear from the docs that call used to be named something else. On Tuesday, January 20, 2015 at 4:54:08 PM UTC-6, Jeff Bezanson wrote: > > Here is a hack that basically works by escaping through the C type system: > > ``` > immutable CFunction{R,A} > f > p::Ptr{Void} > CFunction(f) = new(f, cfunction(f, R, (A,))) > end > > call{R,A}(f::CFunction{R,A}, x) = ccall(f.p, R, (A,), x) > > foo(x::Float64) = 0.0 > goo(x::Float64) = x > > function test1() > for i=1:100000000 > f = foo > r = f(1.0) > goo(r) > end > end > > function test2() > f = CFunction{Float64,Float64}(foo) > for i=1:100000000 > r = f(1.0) > goo(r) > end > end > ``` > > I added an argument to `foo` to increase the generality somewhat. > test1() is the original test case. test2() is the new version. The > CFunction object needs to be constructed outside the loop, but this > can be stored in a data structure and reused anywhere. > > -Jeff > > > On Tue, Jan 20, 2015 at 4:34 PM, Ivar Nesje <iva...@gmail.com > <javascript:>> wrote: > > Originally posted at https://github.com/JuliaLang/julia/issues/9863 > -- Please click here <http://www.e-disclaimer.com/conning/AD21D06B4CC99D2B4F24BA73FB4EED83.htm> for important information regarding this e-mail communication.