The user guide describes clearly how to access the docstring of a function via the help mode of the REPL. But how can I access the docstring without the REPL (from a program)?
I’m not sure what you mean exactly by not using the REPL. Do you mean from within the IDE that you are using?
If you mean accessing it via code, then use @doc
. For example:
julia> @doc Int
Int64 <: Signed
64-bit signed integer type.
Thanks, yes, that is what I meant. This helps.
BTW, I can’t really find much in the official documentation, but it must be somewhere. Do you know where? I get no direct hits when I search for @doc.
The doc search isn’t always great, but here’s a docstring:
help?> @doc
Documentation
≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
Functions, methods and types can be documented by placing a string before the definition:
"""
# The Foo Function
`foo(x)`: Foo the living hell out of `x`.
"""
foo(x) = ...
The @doc macro can be used directly to both set and retrieve documentation / metadata. The macro has special parsing so
that the documented object may occur on the next line:
@doc "blah"
function foo() ...
By default, documentation is written as Markdown, but any object can be used as the first argument.
Documenting objects after they are defined
============================================
You can document an object after its definition by
@doc "foo" function_to_doc
@doc "bar" TypeToDoc
For macros, the syntax is @doc "macro doc" :(@Module.macro) or @doc "macro doc" :(string_macro"") for string macros.
Without the quote :() the expansion of the macro will be documented.
Retrieving Documentation
==========================
You can retrieve docs for functions, macros and other objects as follows:
@doc foo
@doc @time
@doc md""
Functions & Methods
=====================
Placing documentation before a method definition (e.g. function foo() ... or foo() = ...) will cause that specific
method to be documented, as opposed to the whole function. Method docs are concatenated together in the order they were
defined to provide docs for the function.
Thanks, but I was wondering where on Julia Documentation · The Julia Language this is documented.
(There’s a small irony here, looking for information on not using the REPL help by using the REPL help…)
There’s a mention here:
https://docs.julialang.org/en/v1/base/base/#Base.Docs
Most discussion on usage seems to be in the “Advanced usage” section of the documentation documentation:
https://docs.julialang.org/en/v1/manual/documentation/#Advanced-Usage
Great, thanks!
@ nilshg, I just learned today that you’re a friend of MN with whom I work closely! Small world