2

Lets say i want to get the documentation for a function, I'd say

(documentation 'foo 'function) 

but what if I only had foo and function as strings? E.g. "foo" and "function".

What would I have to do to them to make them usable as parameters to the documentation call?

[Side note: I'm using clisp, but I doubt that matters.]

2 Answers 2

8

Use FIND-SYMBOL, not INTERN. If you want to find documentation for an existing function, finding a symbol is enough. INTERN also creates symbols.

CL-USER > (find-symbol "SIN" "COMMON-LISP") SIN :EXTERNAL 

Note that Common Lisp symbols are uppercase internally be default. Thus you need to use an uppercase string to find the corresponding symbol in the corresponding package.

Also note that there actually isn't something like a 'quoted variable'. You want to convert a string to a symbol.

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

2 Comments

So, is (documentation (find-symbol "FOO" "COMMON-LISP-USER") (find-symbol "FUNCTION")) the appropriate way to address the example problem? It works. I just want to make sure I understand this completely. (assuming I'd created a FOO function in the REPL).
also, re your comment about converting it to a symbol, the problem I was having was that there were like 4 different symbol forms I could convert the string to and none of the ones i tried worked (thus the question). Plus I probably wasn't upcasing. So, thanks, and thanks for the extra explanation.
1

Use INTERN to convert a string to a symbol. Make sure you uppercase the strings because, unlike with symbols, the reader will not do it for you:

(tested in SBCL):

* (documentation 'mapcar 'function) "Apply FUNCTION to successive elements of LIST. Return list of FUNCTION return values." * (documentation (intern "MAPCAR") (intern "FUNCTION")) "Apply FUNCTION to successive elements of LIST. Return list of FUNCTION return values." 

5 Comments

Rainer made a good point in his answer, in that it's probably better here to use find-symbol, so that you're not accidentally adding a bunch of new symbols to a package.
@JoshuaTaylor INTERN will create the symbol only if it doesn't yet exist. So both should be equivalent, modulo typing errors, right?
But if there was not already a symbol with a given name, then you probably don't want to create it here. For instance you would not want to create cl:foo just because someone wrote foo.
Agreed. I wont delete the answer so that Rainer's keeps its context. Thanks to both of you.
Sigh, I was editing your answer, while I wanted to edit mine... Sorry for the confusion...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.