Is there a way to access the documentation string associated with a function that is part of a module?
Consider this example:
module Test
export f
"""
f(x)
Return `x` squared.
"""
function f(x)
return x^2
end
end # module Test
using .Test
function getDocString(g) # I would like g::Union{Symbol, String}
return @doc g # unsure what to put here
end
println(getDocString(f))
# note that `println(@doc f)` does work, but it's not what I want.
Running this as a script gives the error:
No documentation found.
Binding `g` does not exist.
Is there a way to write a function that takes a function argument (represented as a symbol/string) and returns its docstring? I’m probably not understanding how modules relate docstrings to their corresponding functions. I know that I can use @doc f
to access function documentation, but I’d like to use symbols/strings to get this result as well. @doc
is great to use in the REPL. However, I’m looking for a more script-oriented approach.
As a clarifying example, say I generated the symbol :f
and I know there’s a function defined in Test
with that name. How would I get f
’s docstring with only a symbol?