Last active
December 28, 2015 00:19
-
-
Save g000001/7412452 to your computer and use it in GitHub Desktop.
This file contains 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 myclass (c2mop:funcallable-standard-object) | |
() | |
(:metaclass c2mop:funcallable-standard-class)) | |
(defmethod call ((obj myclass) mesg &rest args) | |
(error "foo?")) | |
(defmethod initialize-instance :before ((self myclass) | |
&key definition-source lambda-list | |
name) | |
(c2mop:set-funcallable-instance-function self | |
(lambda (mesg &rest args) | |
(apply #'call self mesg args)))) | |
(defclass foo (myclass) | |
((x :initform 0 :initarg :x) | |
(y :initform 1 :initarg :y) | |
(z :initform 2 :initarg :z)) | |
(:metaclass c2mop:funcallable-standard-class)) | |
;;; | |
;;; | |
;;; | |
(defmethod call ((self foo) (mesg (eql :x)) &rest args) | |
(slot-value self 'x)) | |
(defmethod call ((self foo) (mesg (eql :set-x)) &rest args) | |
(setf (slot-value self 'x) (car args))) | |
(defun send (obj &rest mesgs) | |
(apply obj mesgs)) | |
(let ((o (make-instance 'foo :x 42))) | |
(print (send o :x)) | |
(send o :set-x (* 2 (send o :x))) | |
(print (send o :x))) | |
;>> | |
;>> 42 | |
;>> 84 | |
;=> 84 | |
(defclass bar (foo) | |
((a :initform 100)) | |
(:metaclass c2mop:funcallable-standard-class)) | |
(defmethod call ((self foo) (mesg (eql :a)) &rest args) | |
(slot-value self 'a)) | |
(let ((o (make-instance 'bar :x 42))) | |
(print (list (send o :x) (send o :a))) | |
(send o :set-x (* 2 (send o :x))) | |
(print (send o :x))) | |
;>> | |
;>> (42 100) | |
;>> 84 | |
;=> 84 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment