Re: Where to file one defgeneric for two classes and two packages



Mirko.Vukovic@xxxxxxxxx writes:

OK, but how would one then handle the following contrived case:

Suppose I want to draw pictures and lines on a display. For pictures
I just apply the draw method, but for lines, I may want to specify the
line thickness (as I said, the example is contrived).

It seems that I am thus forced to specify draw-picture and draw-line
methods, instead of just draw for each of them.

Presumably your picture and line objects keep track of their own
geometry and are drawn with (draw picture) and (draw line),
respectively. There's no point in having a class if that class doesn't
store any data. I'm just sidestepping your example, of course, but I'm
having trouble understanding why it would be helpful to use a generic
function if it were necessary to call it differently depending on the
type of the object. That doesn't seem very generic to me. Consider:

(defclass picture (graphic)
...)

(defclass line (graphic)
...)

(defgeneric draw (graphic)
(:method ((picture picture)) ...)
(:method ((line line)) ...))

(defparameter *list-of-graphics* (list (make-instance 'picture)
(make-instance 'line)
(make-instance 'line)
(make-instance 'picture)
...))

(dolist (g *list-of-graphics*)
(draw g))

This is the kind of situation I envision calling a generic function
in. I don't know the type of the object I'm drawing (I could check at
run-time, but that's what generic functions do for me) and don't need to
worry about it.

The issue is not a show-stopper for me. I was just surprised that
just providing the object class and specifying (or not) an argument is
not enough data for the compiler to figure out which method to apply.

I don't think it would be a problem for the Lisp system. I think the
reasoning is that it would be pointless. If you're inspecting the type
of your object and collating it with data from some other source,
there's no point in automatic dispatch based on type... you've already
done what the generic function would do and might as well type a few
more letters in the function name.
.



Relevant Pages

  • Re: Custom ScaleMode setting problem
    ... It sets up a picture box in the way that you require. ... In this way you can draw the finished graph at any physical location and size you require, opaquely or transparently, and you can draw it to the printer in a way that takes full advantage of the printer's high resolution. ... Private pOffsetX As Single, pOffsetY As Single ...
    (microsoft.public.vb.general.discussion)
  • Re: lines dont stay on form...
    ... Personally for such jobs I would draw ... On way to achieve what you're after and still use your existing "picture ... Private xCentre As Single, yCentre As Single ... Private Sub Label1_DblClick ...
    (microsoft.public.vb.general.discussion)
  • Re: Unknown pointer problem between Visual Basic and C
    ... Draw into a picture area. ... except drawing from Visual Basic (HDC seems to be wrong). ... I send to the "Visual Basic wrapper" built in C, dimensions and DC pointer ...
    (microsoft.public.win32.programmer.gdi)
  • Re: redraw pictureboxes in image????
    ... own suggested method to perform this job (a Picture Box containing two ... As for your current specific problem, use a Label to hold the "number in the ... at their defaults if you wish) and set its ToolTipText to whatever you want. ... Draw your line between the images using the VB Line method (type the word ...
    (microsoft.public.vb.general.discussion)
  • Re: Resize form problem
    ... The second function is to draw some vertical lines as sort of grid ... 'Work out marker string and position ... I placed that in the Resize Event as well. ... you're loading an image into the Picture property of a Picture Box and then ...
    (microsoft.public.vb.general.discussion)