How can user defined functions (say f
) have meaningful printouts when inspected via the REPL using ?f
or help(f)
For example imagin
In Julia v0.5+ (including more recent Julia Versions like 1.2+), you can write a multiline string above the function definition. (No need for @doc
anymore.)
julia> """
cube(x)
Compute the cube of `x`, ``x^3``.
# Examples
```jldoctest
julia> cube(2)
8
```
"""
function cube(x)
x^3
end
cube
help?> cube
search: Cdouble isexecutable Ac_mul_B Ac_mul_Bc Ac_mul_B! Ac_mul_Bc! cumsum_kbn
cube(x)
Compute the cube of x, x^3.
Examples
≡≡≡≡≡≡≡≡≡≡
julia> cube(2)
8
For more information on properly formatting your docstrings, see the official Julia Documentation.