Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i convert a string to a quoted variable

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.]

like image 624
masukomi Avatar asked Feb 14 '26 08:02

masukomi


2 Answers

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.

like image 134
Rainer Joswig Avatar answered Feb 17 '26 04:02

Rainer Joswig


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."
like image 25
uselpa Avatar answered Feb 17 '26 05:02

uselpa