Created
January 25, 2017 18:40
-
-
Save phoe/2596490bcca9699890865704ac79ff4a to your computer and use it in GitHub Desktop.
How to add slot to defclass
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defclass foo-class (standard-class) ;; we first create a metaclass | |
()) ;; no slots required | |
(defmethod initialize-instance :before ((class foo-class) &key my-argument) | |
(print my-argument)) ;; when we first define the class, just print the arguments | |
(defmethod reinitialize-instance :before ((class foo-class) &key my-argument) | |
(print my-argument)) ;; when we later redefine the class, just print the arguments again | |
(defmethod validate-superclass ((class foo-class) (super standard-class)) | |
t) ;; we need to tell CLOS that STORAGE-CLASS and STANDARD-CLASS are compatible | |
;; see http://metamodular.com/CLOS-MOP/validate-superclass.html for more information on this | |
(defclass bar () ;; superclass: STANDARD-OBJECT | |
() ;; no slots required | |
(:metaclass foo-class) ;; we use the storage-class as the metaclass here | |
(:my-argument 1 2 three four omg)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment