I’d like to have a wrapper for a function, which contains its docstring. This works:
julia> struct MyWrapper f docstring end julia> macro wrap(fdef) fname = fdef.args.args esc(quote Base.@__doc__ $fdef MyWrapper($fname, Base.doc($fname)) end) end @wrap (macro with 1 method) julia> candy = begin "Hello" @wrap choco() = 10 end MyWrapper(choco, Hello )
So far so good. But then this fails:
julia> macro wrap2(fdef) esc(:(annoying_var = @wrap($fdef))) end @wrap2 (macro with 1 method) julia> candy2 = begin "Hello" @wrap2 choco2() = 10 end annoying_var julia> typeof(candy2) Base.Docs.Binding
Not only were the docs not assigned properly, the whole result is wrong. I tried inserting
@__doc__ invocations in the
@wrap2 definition, to no avail.
Is there a better way of doing this? I don’t mind using internals.
To be clear: I’d like
@wrap2 to be like
@wrap, but I do need to assign the result to a local variable in my specific use case, and this causes issues…