How to add short inline documentation to a function?

In C++/Doxygen it is possible to add short documentation e.g.

int myf(int x);   ///< My quick doc

Is it possible to use the same style in Julia/Documenter.jl, without having to write a docstring on its own line, like:

"""My quick doc"""
myf(x) = x+1


I can see that """Add 1 to x """ myf(x) = x+1 works, but the other way around would be much better…

I don’t think there is similar functionality in Julia.

Also, for single line, you may not need the triple quotes (unless you want to use unescaped quotes), so

"stuff" f(x) = 1

would work fine, too.

Finally, if you still don’t like prepending docstrings, you can write a macro

@docafter f(x) = 1 "stuff"

but personally I would just stick with what’s supported.


Just to complement Tamas answers:

  1. The triple quoting has nothing to do with documentation, it is just a convenient way of writing multiline strings. What documents is having a string object before the struct/field/method/function that you what to document.
  2. This said, you can have a simple quoted string above some construct and it will document the same way (they do not need to be in the same line just because they are simple quoted), i.e.
"My documentation of struct A."
struct A
    "My documentation of field b."
    b :: Int
    "My documentation of field c."
    c :: Int
1 Like