LISP 打印函数文档字符串

LISP print function docstring

我只是想打印 LISP 函数的文档字符串。 LISP documentation 在文档类型方面相当模糊,所以我不确定如何做到这一点。这是我目前所拥有的:

(defun pr(x) "This is a docstring!" (+ x 1))
(documentation #'pr t)

我还没有找到关于如何执行此操作的任何简明答案。这哪里错了?

没错。你也可以明确地说 (documentation #'pr 'function).

但是,正如规范还指出的那样:

An implementation is permitted to discard documentation strings at any time for implementation-defined reasons.

所以如果你没有得到文档字符串,你可能需要看看你正在使用的实现的文档,优化设置,你是 运行 解释还是编译等等