ANN LegibleLambdas.jl

#1

LegibleLambas.jl is a package for making anonymous functions whose names are their expressions, ie.

julia> f = @λ(x -> x + 1)
(x -> x + 1)

julia> f(1.0)
2.0

The primary use-case I see for this functionality is for functions which return functions (closures). Suppose I have a function D which operates on a function and gives it’s (finite difference) derivative, I can use LegibleLambdas

D(f, ϵ=1e-10) = @λ(x -> (f(x+ϵ)-f(x))/ϵ)

so that when a user wants to know what D(sin) is, they are shown

julia> D(sin)
(x -> (sin(x + 1e-10) - sin(x)) / 1e-10)

instead of something like

julia> D(sin)
#1 (generic function with 1 method)
13 Likes

#2

It would be nice to do something like this for display of short functions in base; see also

4 Likes

#3

Nice work! I’m already using this in our next release of Yao.jl!

0 Likes

#4

Will it be possible to have this feature directly in julia? So short lambda’s printing will be something like LegibleLambdas by default. We do get nothing from current printings…

2 Likes

#5

I should have mentioned in the original post that this would probably have just rotted away on my list of abandoned repositories if you hadn’t come along with your PR to overhaul the internals and fix a few problems I was unable to figure out, so thank you Roger!

1 Like