in reply to OO, Class::MethodMaker, and get_set
I'd do it something like this in Lisp (not very tested):
(defclass sum () ((a :accessor a :initarg :a :initform 0) (b :accessor b :initarg :b :initform 0) (c :reader c))) (defmethod compute ((self sum)) (setf (slot-value self 'c) (+ (a self) (b self)))) (defmethod initialize-instance :after ((self sum) &key &allow-other-ke +ys) (compute self)) (defmethod (setf a) :after (val (self sum)) (declare (ignore val)) (compute self)) (defmethod (setf b) :after (val (self sum)) (declare (ignore val)) (compute self))
Content of marginal relevance to Perl: Maybe there's something out there that implements something akin to Lisp's :after methods in Perl that would do what you want. I don't know, though.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: semi-OT: Lisp code
by runrig (Abbot) on Apr 01, 2003 at 18:31 UTC | |
by hding (Chaplain) on Apr 01, 2003 at 18:37 UTC |