For example, I want to see what's "inside" of the @time macro. How would I do this?
While it doesn't show you the macro itself, you can see the results of the macro expansion with macroexpand
. For example:
julia> macroexpand(:(@time rand(10)))
:(begin # util.jl, line 38:
local #60#b0 = Base.gc_bytes() # line 39:
local #61#t0 = Base.time_ns() # line 40:
local #62#val = rand(10) # line 41:
local #63#t1 = Base.time_ns() # line 42:
local #64#b1 = Base.gc_bytes() # line 43:
Base.println("elapsed time: ",Base./(Base.-(#63#t1,#61#t0),1.0e9)," seconds (",Base.-(#64#b1,#60#b0)," bytes allocated)") # line 44:
#62#val
end)
In this case, it also shows you where it is defined (util.jl, line 38), but that doesn't always happen. Since macros aren't first class objects themselves, the utilities such as which
/edit
/less
(or their macro equivalents) don't work.
I don't think there's a built in way to do this, but you can search the codebase for "macro X".
This sounds like it would be a useful feature, so unless someone corrects me and it already exists, you could always open an issue requesting it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With