Is there a way to customize how something is printed ina stacktrace? My usecase is the LegibleLambas.jl package which is made for making anonymous functions easier to read:
julia> f = @λ(x -> x + 1)
(x -> x + 1)
but unfortunately, this is only half useful since I don't know how to make it print nicely in a stacktrace. E.g.:
julia> g(x) = f(x)
g (generic function with 1 method)
julia> g("hi")
ERROR: MethodError: no method matching +(::String, ::Int64)
Stacktrace:
[1] (::var"#19#20")(x::String)
@ Main ./REPL[34]:1
[2] (::LegibleLambda{var"#19#20"})(args::String)
@ LegibleLambdas ~/.julia/dev/LegibleLambdas/src/LegibleLambdas.jl:44
[3] g(x::String)
@ Main ./REPL[35]:1
[4] top-level scope
@ REPL[36]:1
It'd be nice if [2]
here could say (x -> x + 1)(args::String)
instead
You are looking for Base.show_signature_function
, which is not exported, so use at your own risk. Only the type information is preserved in stacktraces though, so you don't get an instance of f
, but only the type of f
.
Last updated: Nov 22 2024 at 04:41 UTC