Re: Yet another 'when to use macros' question....



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
.



Relevant Pages

  • Re: PROJECT PROBLEMS
    ... i'm just a newbie here and i think this is the best place ... > said it is 'filtering the wanted the signal'. ... > signal,the x-axis will show the units in an increasing order, within ... > again to what the plot is saying. ...
    (comp.soft-sys.matlab)
  • PROJECT PROBLEMS
    ... i'm just a newbie here and i think this is the best place ... said it is 'filtering the wanted the signal'. ... signal,the x-axis will show the units in an increasing order, within ... again to what the plot is saying. ...
    (comp.soft-sys.matlab)
  • Re: Adding a manually controlled Line to XY scatter
    ... Given an XY scatter plot with the following data; ... out by a process called zero correction. ... In this example the line crosses the X-axis ... What I would like to do is be able to put the line in place adjusting ...
    (microsoft.public.excel.charting)
  • Re: Matlab FFT
    ... For part A I import the data in matlab and then plot it using the plot ... should it be in any diff format in terms of x-axis. ... although if my FFT graph is corrct in the next part the X ...
    (comp.dsp)
  • Re: Yet another when to use macros question....
    ... go ahead and use keyword args so you do not end up with strings ... The plot creates instances of axis, legend, etc. ... I'm not sure I understand your question, but to the extent I do, I think you'll be fine if you just do your initialization in an initialize-instance:after method. ... Thus any initialization code that is provided by the author of the class you are subclassing should run before your initialize-instance method and thus all the object's slots that would be initialized if you just made an instance of the superclass will be initialized by the time your code sees it. ...
    (comp.lang.lisp)