CodeTracking.jl
CodeTracking.jl copied to clipboard
[Docs] Getting Started
CodeTracking [...] provides an interface for obtaining:
the strings and expressions of method definitions
How does CodeTracking do the above?
using CodeTracking, Revise
f = x -> 2 * x^3 + 1
julia> @code_expr f
ERROR: LoadError: expression is not a function call or symbol
julia> @code_string f(1)
ERROR: LoadError: MethodError: no method matching getindex(::Nothing, ::Int64)
julia> print(@code_expr f(1))
nothing
I did not post on discourse because there are existing discussions and unfortunately I haven't been able to understand them. Can the above be done? If so, an example would be greatly appreciated. I'm opening an issue, so perhaps a word or two could be added to the readme. I won't be offended if you close it. :-)
Comments in these discussions point to CodeTracking, but unfortunately do not show examples of usage:
https://discourse.julialang.org/t/source-code-of-a-function/4499/12
https://discourse.julialang.org/t/printing-the-body-of-a-defined-function/23439/2
https://discourse.julialang.org/t/show-code-macro/46050
Discussion where the plot thickens:
https://discourse.julialang.org/t/get-function-as-expr/51886/5
julia> using CodeTracking, Revise
julia> f(x) = 2 * x^3 + 1
f (generic function with 1 method)
julia> @code_expr f(1)
:(f(x) = begin
#= REPL[2]:1 =#
2 * x ^ 3 + 1
end)