When I do this:
(defparameter thing #'(lambda () (+ 1 1)))
The returned value for thing
is
#<FUNCTION (LAMBDA ()) {53A11BEB}>
This print out looks a lot like the print-object for a CLOS.
So, I thought id like to see the actual function detail in the print-object
.
I cannot seem to find out the name of the function object to use in my list-class-slots
function:
(defun list-class-slots (class)
(mapcar #'sb-mop::slot-definition-name
(sb-mop::class-direct-slots (class-of (make-instance class)))))
I tried sb-mop::funcallable-standard-class
but this returns nil. I also tried function
and the error told me to use the funcallable-standard-class.
Am I wrong here? is the original lambda printout NOT related to CLOS at all? if not, what is the source of the function printout?
A function created with lambda
is an object, yes. It's an instance of the system class function
:
* (class-of thing)
#<SB-PCL:SYSTEM-CLASS COMMON-LISP:FUNCTION>
Functions are printed in an implementation-dependent manner, in practice often in the convention for an unreadable value (#<...>
). It appears that SBCL has a specialization of the print-object
generic method for functions.
* (find-method #'print-object '() (mapcar #'find-class '(function t)))
#<STANDARD-METHOD COMMON-LISP:PRINT-OBJECT #'T {100042B4C3}>
Indeed, here it is. You can poke around in it to see how it works.