class-name
class-name Standard Generic Function
Syntax:
class-name class ! name
Method Signatures:
class-name (class class)
Arguments and Values:
class—a class object.
name—a symbol.
Description:
Returns the name of the given class.
See Also:
find-class, Section 4.3 (Classes)
Notes:
If S is a symbol such that S =(class-name C) and C =(find-class S), then S is the proper name of C. For further discussion, see Section 4.3 (Classes).
The name of an anonymous class is nil.
(setf class-name) Standard Generic Function
Syntax:
(setf class-name) new-value class ! new-value
Method Signatures:
(setf class-name) new-value (class class)
Arguments and Values:
new-value—a symbol.
class—a class.
Description:
The generic function (setf class-name) sets the name of a class object.
See Also:
find-class, proper name, Section 4.3 (Classes)
Expanded Reference: class-name
Getting the Name of a Class
class-name returns the symbol that names a class object. It is the inverse of find-class.
(class-name (find-class 'integer))
=> INTEGER
(class-name (find-class 'string))
=> STRING
With User-Defined Classes
(defclass vehicle ()
((make :initarg :make)))
(class-name (find-class 'vehicle))
=> VEHICLE
Using class-name with class-of
A common pattern is to get the class name of an object by combining class-of and class-name.
(defclass dog () ())
(let ((d (make-instance 'dog)))
(class-name (class-of d)))
=> DOG
Setting the Class Name
(setf class-name) can change the name stored in a class object. Note that this does not update find-class.
(defclass temp-class () ())
(let ((cls (find-class 'temp-class)))
(setf (class-name cls) 'renamed-class)
(class-name cls))
=> RENAMED-CLASS