Re: Generics vs. Message passing: object namespaces
"Matt Knox" <[email protected]> Fri, 23 Feb 2007 16:25:50 -0500
| Newsgroups | gmane.comp.lang.lightweight |
|---|---|
| Message-ID | <[email protected]> |
On 2/23/07, Michael Walter <[email protected]> wrote: > > On 2/23/07, Matt Knox <[email protected]> wrote: > > On 2/23/07, Michael Walter <[email protected]> wrote: > > > On 2/23/07, [email protected] <[email protected]> wrote: > > > > > If I understand it correctly, your point is that if you need the > draw > > > > > method from gun, picture, blood, and duel modules, that in an > > > > > object-dispatch system, you can say: > > > > > > > > > > gun.draw args > > > > > duel.draw args > > > > > ...etc. > > > > > > > > > > instead of > > > > > (draw_gun gun args) > > > > > > > > > > But it seems that it should be trivial to have, in a CLOS-style > > generic > > > > > function system, 'draw' bound to a function that would look at the > > type of > > > > > its first argument and dispatch to the appropriate GF. Then you'd > > have: > > > > > > > > > > (draw gun args) > > > > > ... > > > > > and the only differences would be syntax and the ease with which > > > > > autocompletion could be done. > > > > > > > > > > Am I missing something? > > > > > > > > > > > > No, I think that is correct, but that is not how CLOS-style > generic > > > > OOP works, the original subject of criticism. [...] > > > > > > In what way is using dynamic dispatch not how CLOS-style generic OOP > > > works? I mean, this seems to be pretty much what defgeneric/defmethod > > > are for. > > > > > > Regards, > > > Michael > > > > > > > The difference is that if you define 3 different GFs (not different > methods > > on a single gf, but 3 different functions) in different source files, > each > > with the same name, CLOS does not automatically smash them together into > a > > sngle, more generic function. > > But why don't you define 3 different methods of the same generic function? > > Regards, > Michael > Because you might not have written all three modules. It shouldn't be hard to make the package system create a dispatch function when it detected function name collisions. Then, as long as the argument types encode enough information to decide which method to call, you're fine. -- (def (eval e l d c) (if (atom? e) ((ahandler (type e)) e l d c) (eval (car e) l d (fun (x) (evapp x (cdr e) l d c)))))