I have some code that takes as an argument a function:

(defun message-name (fn)

I would like to be able to, if the function has a name, message it. For example, if called this way:

(message-name #'get-buffer)

I would like this code to message The function's name is get-buffer:

(defun message-name (fn)
  (message "The function's name is %s."
           (????? fn)))

If you are passing a symbol (as in your example) then yes, you can get the symbol-name of the argument. e.g.:

(symbol-name fn)

A "function passed as an argument" might also be a function object, though, and you can't pull a symbol name from that. You would have to search for a symbol which had the same value in its function cell.

  • 2
    Small addition: you may want to check if fn is a symbol first with symbolp, as symbol-name will throw an error if fn is not a symbol. – JeanPierre Aug 11 '16 at 7:47

Your Answer

