1

I am simply trying to print a LISP function's documentation string. The LISP documentation is fairly ambiguous with regard to doctypes, so I am unsure as to how to do this. This is what I have so far:

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

I haven't found any concise answers on how to do this. Where is this wrong?

1 Answer 1

5

It's right. You could also explicitly say (documentation #'pr 'function).

However, as the Spec also notes:

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

So if you do not get the docstring, you may have to take a look at the documentation of the implementation you are using, the optimization settings, whether you are running interpreted or compiled etc.

Sign up to request clarification or add additional context in comments.

4 Comments

How would I print just the function's name?
You can try the third value of (function-lambda-expression some-fun), but the above caveats apply as well.
(print (function-lambda-expression 'something)) yields (LAMBDA (X) "hiii" (DECLARE (SYSTEM::IN-DEFUN SOMETHING)) (BLOCK SOMETHING (+ X 1))) , but I would just like to print something. How would I do that?
It's the third value. (nth-value 2 (function-lambda-expression #'something)).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.