【问题标题】:Print a docstring of a program to stdout in Julia在 Julia 中将程序的文档字符串打印到标准输出
【发布时间】:2021-09-05 21:43:21
【问题描述】:

Julia 在命令行上接受?sin 以显示帮助文本。我相信这样的帮助文本是作为文档字符串实现的。我想在运行时从我的 Julia 程序中打印这样的文档字符串。该怎么做?

【问题讨论】:

    标签: julia docstring


    【解决方案1】:
    julia> @doc sin
      sin(x)
    
      Compute sine of x, where x is in radians.
    
      sin(A::AbstractMatrix)
    
      Compute the matrix sine of a square matrix A.
    
      If A is symmetric or Hermitian, its eigendecomposition (eigen) is used to compute the
      sine. Otherwise, the sine is determined by calling exp.
    
      Examples
      ≡≡≡≡≡≡≡≡≡≡
    
      julia> sin(fill(1.0, (2,2)))
      2×2 Matrix{Float64}:
       0.454649  0.454649
       0.454649  0.454649
    

    【讨论】:

    • 你也可以直接使用@doc宏(例如@doc sin)。
    • 哦,谢谢!我不知道@doc 返回了 md 字符串。
    • 我写了一个简单的函数来测试当前的想法。在 VS Code 中,@doc sin 将 markdown 输出格式化为应有的颜色和所有内容。在 Linux shell 中执行相同的程序不会从@doc sin 得到任何输出。是否可以在 shell 中获得格式化输出?
    • VSCode(可能)在返回值上自动调用display。在非交互式环境中,您必须自己在结果上调用display/show
    • 我猜你忘记打印了。 julia -e "print(@doc sin)" 。或者,如果您想要颜色和格式,julia -e "display(@doc sin)"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-01
    • 2010-10-15
    • 2012-09-02
    • 2015-08-31
    • 2012-09-29
    • 1970-01-01
    相关资源
    最近更新 更多