CodeTracking.jl
CodeTracking.jl copied to clipboard
Revise should track macro-created functions defined in the REPL
macro makefn(name)
name = Symbol(name)
quote
$(esc(name))() = print("hello")
end
end
julia> @makefn f
f (generic function with 1 method)
julia> f()
hello
julia> @code_string f()
" \$(esc(name))() = println(\"hello\")"
In an ideal world, @code_string f() would return something like f() = println(\"hello\")".
@code_string is designed to operate on raw source files---it's the fallback in case all the fancy Revise-based machinery fails. There's basically no way this can work.
It seems that Revise cannot track macro-created methods at the REPL, either. But if you put it in a file, then
julia> using CodeTracking, Revise
julia> includet("/tmp/ct.jl")
julia> definition(Expr, only(methods(f)))
:(#= /tmp/ct.jl:8 =# @makefn f)
julia> @code_expr f()
:(#= /tmp/ct.jl:8 =# @makefn f)
I think we can narrow the issue here, so I've edited the title.