Just an update, it had been bothering me in the back of my head for some time now that LegibleLambdas was producing slow closures. I’ve now updated it to version 0.3.0 where closures do not impose a runtime performance overhead! I’ve also lightened the dependancies.
julia> using LegibleLambdas
julia> f(x) = @λ y -> x + y;
julia> f(1)
(y -> 1 + y)
julia> f(2)
(y -> 2 + y)
julia> let x = Ref(1), y = Ref(2)
@btime f($x[])($y[])
end;
1.299 ns (0 allocations: 0 bytes)
julia> D1(f, ϵ=1e-10) = @λ(x -> (f(x+ϵ) - f(x))/ϵ);
julia> D2(f, ϵ=1e-10) = x -> (f(x+ϵ) - f(x))/ϵ;
julia> let x = Ref(1.0)
@btime D1(sin)($x[])
@btime D2(sin)($x[])
end;
12.975 ns (0 allocations: 0 bytes)
12.975 ns (0 allocations: 0 bytes)
julia> D1(sin)
(x -> ((sin)(x + 1.0e-10) - (sin)(x)) / 1.0e-10)
julia> D2(sin)
#14 (generic function with 1 method)
Happy λs.