method combinations
- From: Ari Krupnik <ari@xxxxxxxx>
- Date: Mon, 17 Jul 2006 19:01:49 -0700
I have a class that has methods specialized on it that are
expensive. I want to inherit from this class to include slots that can
hold precomputed values of these expensive methods. I want to make it
so that if I have an instance of the superclass, the expensive method
will be called, but if I have an instance of the subclass, the slot
value will be returned. I'm running into difficulties initializing the
slots. I need to invoke the expensive method, but since I have a
reference to the inheriting class, a call to to the function resolves
to a reader method. In Java, I'd say `super.c()' instead of
`c()'. What is the CLOS equivalent?
The line that I'm having trouble with is marked `tautology' below.
Ari.
(defclass dynamic ()
(slot-a :reader a)
(slot-b :reader b)
(defmethod c ((dy dynamic))
;expensive computations
)
(defmethod d ((dy dynamic))
;expensive computations
)
(defclass precomputed (dynamic)
(slot-c :reader c)
(slot-d :reader d))
(defmethod initialize-instance :after ((pc precomputed) &key c d)
(with-slots (slot-c slot-d) pc
(setf slot-c (c p)) ; tautology
(setf slot-d (d p))))
--
Elections only count as free and trials as fair if you can lose money
betting on the outcome.
.
- Follow-Ups:
- Re: method combinations
- From: Jack Unrue
- Re: method combinations
- Prev by Date: Re: Amazon used lisp & C exclusively?
- Next by Date: Re: Amazon used lisp & C exclusively? (clc,cll)
- Previous by thread: Initial Thoughts on Montezuma
- Next by thread: Re: method combinations
- Index(es):
Relevant Pages
|