# Accessing the docstring from within a macro, @\_\_doc\_\_ troubles

**URL:** <https://discourse.julialang.org/t/accessing-the-docstring-from-within-a-macro-doc-troubles/84937>\
**Category:** General Usage\
**Created:** [July 28, 2022, 8:32pm UTC](https://discourse.julialang.org/t/accessing-the-docstring-from-within-a-macro-doc-troubles/84937 "2022-07-28T20:32:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Post date:** [July 28, 2022, 8:32pm UTC](https://discourse.julialang.org/t/accessing-the-docstring-from-within-a-macro-doc-troubles/84937/1 "2022-07-28T20:32:34Z")

</div>

I’d like to have a wrapper for a function, which contains its docstring. This works:

```julia
julia> struct MyWrapper
          f
          docstring
       end

julia> macro wrap(fdef)
           fname = fdef.args[1].args[1]
           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
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…
