Skip to content

Instantly share code, notes, and snippets.

@g000001
Created July 31, 2016 07:50
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 g000001/3996363eb492cc46b77179793e75ae89 to your computer and use it in GitHub Desktop.
Save g000001/3996363eb492cc46b77179793e75ae89 to your computer and use it in GitHub Desktop.
(defclass symbolic-object-class (standard-class)
())
(defmethod allocate-instance
((class symbolic-object-class) &rest args &key)
(let ((inst (gensym "SYMBOLIC-OBJECT-")))
(setf (get inst :class) class)
(dolist (slot (class-slots class) inst)
(setf (get inst (clos:slot-definition-name slot)) :unbound))))
(defmethod shared-initialize ((inst symbol) slot-names &rest args
&key)
(if (or (eq T inst)
(not (typep (get inst :class) 'class)))
(call-next-method)
(dolist (slot (class-slots (get inst :class)) inst)
(setf (get inst (clos:slot-definition-name slot))
(slot-definition-initform slot)))))
(defmethod c2mop:slot-value-using-class
((class (eql (find-class 'symbol))) inst slot-name)
(get inst slot-name))
(defmethod (setf c2mop:slot-value-using-class)
(newval (class (eql (find-class 'symbol))) inst slot-name)
(setf (get inst slot-name) newval))
(defclass foo ()
((a :initform 0)
(b :initform 1)
(c :initform 2))
(:metaclass symbolic-object-class))
(let ((inst (make-instance 'foo)))
(setf (slot-value inst 'a) 42)
(symbol-plist inst))
;→ (c 2 b 1 a 42 :class #<symbolic-object-class foo 41A0085653>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment