(defun rget (prop obj) (multiple-value-bind (val in) (gethash prop obj) (if in (values val in) (let ((par (gethash :parent obj))) (and par (rget prop par)))))) (defun tell (obj message &rest args) (apply (rget message obj) obj args)) (deftest !oo0 () (test "radius = 2 area = 12.566370614359172d0" (with-output-to-string (str) (!oo0-prim str)))) (defun !oo0-prim (&optional (str t)) (let (circle-class our-circle) (setf circle-class (make-hash-table) our-circle (make-hash-table) (gethash :parent our-circle) circle-class (gethash 'radius our-circle) 2 (gethash 'area circle-class) #'(lambda (x) (* pi (expt (rget 'radius x) 2 )))) (format str "~&radius = ~a area = ~a~%" (rget 'radius our-circle) (tell our-circle 'area)))) #| comments: 1a) everything hashed. not the fastest option 1b) ugly syntax. error prone. ideally, want someway to batch common operations 1c) association, polymorphishm, 1d) no inheritance 1e) no concept of "class" seperaete to "instance" (anything can be something anything else can inherit from 1f) no encapulation : variables referenced different to methods where to go from here? ====================== (defun tell% (obj message &rest args) (let ((what (rget message obj))) (if (functionp what) (apply (rget message obj) obj args) what))) ; setf is a problem. can't (setf (tell *timm* 'age) 22) 322 21 100 404 168 Background ========== Definining accessors --------------------- (Graham, p100) By making the first argument to defun a list of the form (setf / ) , you definewhathappenswhenthefirstargumenttos e t fisacallto f. The following pair of functions defines primo as a synonym for car: (defun primo (1st) (car 1st)) (defun (setf primo) (val 1st) (setf (car 1st) val)) In the definition of a function whose name is of the form (setf / ) , the first parameter represents the new value, and the remaining parameters represent arguments to/.° Now any setf of primo will be a call to the latter function above: > (let ((x (list 'a 5b >c))) (setf (primo x) 480) x) (480 B C) |#