(defclass myclass ()
  (iv1 iv2 iv3
       (cv1 :allocation :class)))

(defclass myclass2 (standard-object)   ; same as above
  (iv1 iv2 iv3
       (cv1 :allocation :class))
  (:metaclass standard-class))

(setq i1 (make-instance 'myclass))

(class-of i1) -> class object of i1

(class-name (class-of i1))

(find-class 'myclass) -> class object

(type-of i1)  ->  MYCLASS

(describe i1)

(setf (slot-value i1 'iv2) 55)

(defmacro set-slot (i s v)
  `(setf (slot-value ,i ',s) ,v))
(defmacro get-slot (i s)
  `(slot-value ,i ',s))

(slot-value i1 'iv2)

(with-slots (iv1 iv2 iv3)  i1
      (setq iv2 'hello))
      
(defmethod do-nothing ((self myclass))  ;  This will create a generic function too if it doesn't already exist
  "in do-nothing")

(do-nothing i1)


(setq standard-object (find-class 'standard-object))

(setq standard-class (find-class 'standard-class))

(class-of standard-object) -> standard-class

(class-of standard-class) -> standard-class

(class-direct-superclasses standard-class) -> non-standard function call

; Need:
; (defclass2 class-name (super-class-list) (class-variables) (instance-variables))
;
; Becomes:
; (defclass META-class-name (META-super-class-list) (class-variables) (:metaclass standard-class))
; (defclass class-name (super-class-list) (instance-variables) (:metaclass META-class-name))
; Problem because of missing meta-standard-object, meta-standard-class, etc.

(defclass meta-class1 (standard-class)
  (cv1 cv2 cv3)
  (:metaclass standard-class))

(defvar sc (find-class 'standard-class))
(defvar mc1 (find-class 'meta-class1))

(defclass class1 (standard-object)
  (iv1 iv2 iv3)
  (:metaclass meta-class1))

(defclass meta-class2 (meta-class1)
  (cv4 cv5 cv6)
  (:metaclass standard-class))

(defclass class2 (class1)
  (iv4 iv5 iv6)
  (:metaclass meta-class2))

(setq i1 (make-instance 'class1))
(setq i2 (make-instance 'class2))

; instance initialization method
(defmethod allocate-instance :after ((class meta-class1) &key)
  ...)

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-1) was last changed on 02-May-2011 21:13 by UnknownAuthor