Skip to content

Instantly share code, notes, and snippets.

@phoe
Created January 25, 2017 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phoe/2596490bcca9699890865704ac79ff4a to your computer and use it in GitHub Desktop.
Save phoe/2596490bcca9699890865704ac79ff4a to your computer and use it in GitHub Desktop.
How to add slot to defclass
(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