Reputation:
Is it possible in common lisp to convert a function to a symbol or a string for further use? What i mean is to get a "+"
or #:|+|
from #'+
.
Upvotes: 4
Views: 726
Reputation: 1289
(defun function-name (fn)
(string-downcase (symbol-name (nth-value 2 (function-lambda-expression fn)))))
(function-name #'atom) => "atom"
Upvotes: 0
Reputation: 60014
The only standard way is
function-lambda-expression
which is not guaranteed to return anything useful.
Neverless, both CLISP and SBCL return the actual function name:
(nth-value 2 (function-lambda-expression #'+))
==> +
or, if you wish,
(symbol-name (nth-value 2 (function-lambda-expression #'+)))
==> "+"
Upvotes: 8
Reputation: 139261
CL-USER> (nth-value 2 (function-lambda-expression #'sin))
SIN
Upvotes: 5