Nice way to display functions

I would use something like:

immutable ShortFun{T<:Function}
    f::T
    expr
end
# This printing could be made nicer by removing the `begin` that appears. See MacroTools
Base.show(io::IO, sf::ShortFun) = print(io, sf.expr)
# Beware that kwargs will make this slow; remove them if you don't need them
# and performance is a concern
(sf::ShortFun)(args...; kwargs...) = sf.f(args...; kwargs...)
macro shortfun(expr)
    esc(:(ShortFun($expr, $(Expr(:quote, expr)))))
end
f = @shortfun x -> 2+x
1 Like