How to make user defined function descriptions (“docstrings”) available to julia REPL?

后端 未结 2 1780
执念已碎
执念已碎 2021-01-30 12:01

How can user defined functions (say f) have meaningful printouts when inspected via the REPL using ?for help(f)

For example imagin

2条回答
  •  悲哀的现实
    2021-01-30 13:08

    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.

提交回复
热议问题