From: mlucius@... (Mike Lucius) Date: 2002-09-13T14:22:22+09:00 Subject: Re: Multimethods (was Re: Larry Wall's comments on Ruby) Paul Brannan wrote in message news:<20020912103044.P25425@atdesk.com>... > On Thu, Sep 12, 2002 at 02:59:22PM +0900, Mike Lucius wrote: > > Multimethod dispatch (which is like C++ function overloading, but not > > quite)is when there are two(or more) receivers. It is exactly like > > C++ function overloading except the method would presumably have > > access to the internal state of both(all) instances dispatched upon. > > With C++ function overloading the function to call is picked at > compile-time. Wouldn't the multimethod to call be picked at run-time > (like virtual functions)? Yes, you're right. OO Polymorphism is a limited way of doing safe dynamic typing. > > > i.e. it has the status of "method" for both classes. C++ doesn't > > support this idea directly, but Alexandrescu uses Template Programming > > to make a fair approximation (using double-dispatch IIRC). > > > > Function overloading does the same thing, but functions are not > > methods and this limits their usefulness. > > What is the difference between a virtual member function and a method? In C++ a plain old 'function' does not belong to any class. A 'member function' is the C++ way of saying a method(i.e. it belongs to a class). In ruby all 'functions' belong to some class although this is not apparent to the casual observer. In C++ a 'virtual member function' can be overridden by a derived class. In Ruby (and other languages) all methods can be overridden so there is no such distinction made. > > > > > In C++ generic functions are implemented by the compiler generating > > overloaded functions as required. IMO it is very ugly > > These overloaded functions are generated by templates. Having a > different function generated at compile-time for every combination of > parameters may be ugly, but does offer speed. You can get a similar > effect as Ruby if everything inherits from a common base class and you > add a little bit of extra type information to your classes (XTTI > perhaps?). Sorry, I meant the syntax is ugly. You're right the resulting code is fast. However, I can hardly read the stuff and I have no trouble understanding Perl :) I think extending C++ is useless, its overextended now. I've been looking for alternatives to C++, by which I mean a type-safe compiled(fast) language that has al or most of the goodies I like about Ruby. The best I've found so far is OCaml ( http://www.ocaml.org ), the biggest drawback to OCaml is that it is not very popular. Here is another place to read about this stuff: http://c2.com/cgi/wiki?GenericFunction Mike Lucius