juliadocumentation

Julia doc comment with a shell line (with $ symbol)


I tried to write a doc comment above

function main()

like so

"""
Program arguments:

    $ julia my_julia_program.jl DATE

DATE format should be `yyyymmdd`
"""
function main()

However, this resulted in an error:

ERROR: LoadError: syntax: invalid interpolation syntax: "$ "

My guess would be that Julia has tried to interpret this doc comment as an example code which is runnable. (Rust has the same concept - it is possible to write unit tests and examples in doc comments, which can then be run by cargo test.)

Can anyone advise me on what I should to do fix this? I wanted to include the $ sign here to indicate to the reader that this line is a command line which should be run from the shell. Hence the $.


Solution

  • You cannot put a $ sign in a doc comment without escaping it first.

    Backslash (escape) is required:

    """
    Program arguments:
    
        \$ julia my_julia_program.jl DATE
    
    DATE format should be `yyyymmdd`
    """
    function main()