Re: Yet another 'when to use macros' question....
- From: Kenny Tilton <NOktiltonSPAM@xxxxxxxxxx>
- Date: Thu, 02 Feb 2006 04:14:37 GMT
Sorry, been banging my head against my own code all day.
Jonathon McKitrick wrote:
Kenny Tilton wrote:
Finally, go ahead and use keyword args so you do not end up with strings of unlabelled values like ... 21 21 nil 45 7...
You can combine this because the initialize methods &allow-other-keys, so you do not even have to give the plot class the slots for what are now parameters to your macro.
I'm trying to figure out one tricky part. The initialize-instance
method of a class I have sub-classed creates additional internal
objects.
I should have mentioned that I noticed that and it worries me. It does make it hard to author the resulting interface, because you are trying to fabricate all these things at once, so you will be losing control over how the internal objects get authored.
Overall, you have bitten off a lot as a newbie, and are creating problems for yourself with your own design choices.
One thing you should do is have, as just one example, a slot for x-axis. That normally gets populated by an initializer, but if you supply one, boom, end of story. Your initializer just has to say (unless x-axis....).
OK, that guarantees you complete flexibility. Now about overriding superclass behavior. Hard to do with after methods, as you have discovered. I would take an approach like this:
If the value supplied for x-axis is an instance, leave it alone. If it is a symbol:
(setf (x-axis self) (make-instance (x-axis self) :plot self))
Two things here:
(1) Let the class of the x-axis worry about initializing its own ass
(2) yes, the plot must have attributes sufficient to tell the x-axis how to implement itself, unless:
If the value supplied for x-axis is a list, you:
(setf (x-axis self) (apply 'make-instance (car (x-axis self))
:plot self
(cdr (x-axis self))))[Just typing here so parens may not align etc]
The idea is that you stay out of the way and let make-instance work, even to the extent of allowing the make-instance of internal instances to be programmed by the surrounding code.
(I think I recall you already doing something like this for the axes in the macro version.)
Another trick is:
If the value supplied for x-axis is a function, you:
(setf (x-axis self) (funcall (x-axis self) self))
Now you are having all sorts of fun, with a closure that can do anything including use arbitray closed-over variables. This is the best way to avoid loading up the xy-plot with a kazillion attributes for all the internal instances.
One final note. One trick for handling the subclassing problem as a whole would be to have initialize-instance :after methods simply massage the parameterization in the x-axis slot, then have an i-i :around method that looks roughly like:
(defmethod ii :around ((self xy-plot) &rest initargs)
(call-next-method) ;; let all :after methods run
(here-and-only-here-make-an-axis))But I kinda like the idea of just having xy-plot have the ii :after method and letting it make whatever x-axis you need, using all the tricks I outlined for specifying x-axis (instance, class name, class name and args, closure factory) to easily author your x-axis.
kenny .
- References:
- Yet another 'when to use macros' question....
- From: Jonathon McKitrick
- Re: Yet another 'when to use macros' question....
- From: Pascal Costanza
- Re: Yet another 'when to use macros' question....
- From: Jonathon McKitrick
- Re: Yet another 'when to use macros' question....
- From: Kenny Tilton
- Re: Yet another 'when to use macros' question....
- From: Jonathon McKitrick
- Yet another 'when to use macros' question....
- Prev by Date: Re: New Lisp catch-phrase (?)
- Next by Date: Re: Yet another 'when to use macros' question....
- Previous by thread: Re: Yet another 'when to use macros' question....
- Next by thread: Re: Yet another 'when to use macros' question....
- Index(es):
Relevant Pages
|