www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Any news on multimethods?

reply =?ISO-8859-1?Q?Jari-Matti_M=E4kel=E4?= <jmjmak utu.fi.invalid> writes:
About 1,5 year ago there was short discussion about native multimethods
in D on the NG. Well, is there any possibility to make them native on
the language level. It's a bit annoying to use them via external libraries.
Oct 12 2006
parent reply Bruno Medeiros <brunodomedeiros+spam com.gmail> writes:
Jari-Matti Mäkelä wrote:
 About 1,5 year ago there was short discussion about native multimethods
 in D on the NG. Well, is there any possibility to make them native on
 the language level. It's a bit annoying to use them via external libraries.

What's wrong with the library approach? (and what multimethods library are you using?) -- Bruno Medeiros - MSc in CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
Oct 16 2006
parent reply =?ISO-8859-1?Q?Jari-Matti_M=E4kel=E4?= <jmjmak utu.fi.invalid> writes:
Bruno Medeiros wrote:
 Jari-Matti Mäkelä wrote:
 About 1,5 year ago there was short discussion about native multimethods
 in D on the NG. Well, is there any possibility to make them native on
 the language level. It's a bit annoying to use them via external
 libraries.

What's wrong with the library approach?

Well, nothing in particular. It's just a bit more illustrative to use a syntax like void method(foo bar) { .. } and support multimethods on the language level without extra 3rd party wrappers. Of course it adds more bloat in general, but I don't really know what D is trying to be now. It's too heavy to be a system programming language (out of the box) and it lacks many high level features that are needed in large scale software projects. Double dispatch is a very primitive feature and multimethods are one possible way to implement it.
 (and what multimethods library
 are you using?)

I was testing the old hack by Pragma. There was a newer version of it somewhere but my newsreader was not able to open it.
Oct 16 2006
next sibling parent Pragma <ericanderton yahoo.removeme.com> writes:
Jari-Matti Mäkelä wrote:
 Bruno Medeiros wrote:
 Jari-Matti Mäkelä wrote:
 About 1,5 year ago there was short discussion about native multimethods
 in D on the NG. Well, is there any possibility to make them native on
 the language level. It's a bit annoying to use them via external
 libraries.


Well, nothing in particular. It's just a bit more illustrative to use a syntax like void method(foo bar) { .. } and support multimethods on the language level without extra 3rd party wrappers. Of course it adds more bloat in general, but I don't really know what D is trying to be now. It's too heavy to be a system programming language (out of the box) and it lacks many high level features that are needed in large scale software projects. Double dispatch is a very primitive feature and multimethods are one possible way to implement it.
 (and what multimethods library
 are you using?)

I was testing the old hack by Pragma. There was a newer version of it somewhere but my newsreader was not able to open it.

That old thing? Template coding has grown by leaps and bounds since, and I'm sure there's a better version in the wild somewhere. There was also a discussion recently regarding "template varargs" or something similar for D. A feature like that would making writing a template multimethod library a piece of cake. IMO, having that support would almost be a fair trade-off for formal multimethods. -- - EricAnderton at yahoo
Oct 16 2006
prev sibling parent Bruno Medeiros <brunodomedeiros+spam com.gmail> writes:
Jari-Matti Mäkelä wrote:
 Bruno Medeiros wrote:
 Jari-Matti Mäkelä wrote:
 About 1,5 year ago there was short discussion about native multimethods
 in D on the NG. Well, is there any possibility to make them native on
 the language level. It's a bit annoying to use them via external
 libraries.


Well, nothing in particular. It's just a bit more illustrative to use a syntax like void method(foo bar) { .. }

It is? I'm looking at that code segment and I have no ideia what it means.
 and support multimethods on the language level without extra 3rd party
 wrappers. Of course it adds more bloat in general, but I don't really
 know what D is trying to be now. It's too heavy to be a system
 programming language (out of the box) and it lacks many high level
 features that are needed in large scale software projects. Double
 dispatch is a very primitive feature and multimethods are one possible
 way to implement it.
 
 (and what multimethods library
 are you using?)

I was testing the old hack by Pragma. There was a newer version of it somewhere but my newsreader was not able to open it.

I made a simple and experimental multimethods(multiple dispatch function) implementation not so long ago. It didn't work due to some DMD bugs (which have been fixed meanwhile) nor was it a complete implementation (I just wanted to see if and how it could be made), but the point is that it showed that a MDF implementation could be implemented library-side in a way almost (if not completely) as good as a in-language one. For reference here is how the user can use a MDF: // Define the MDF dispatcher MultiDispatchFunction!(bool function(Shape, Shape)) checkCollisionMDF; // Add dispatches: checkCollisionMDF.AddDispatch(&checkCollisionCC); checkCollisionMDF.AddDispatch(&checkCollisionCR); checkCollisionMDF.AddDispatch(&checkCollisionRC); checkCollisionMDF.AddDispatch(&checkCollisionRR); // Call: checkCollisionMDF.call(new Circle, new Circle); checkCollisionMDF.call(new Rect, new Rect); checkCollisionMDF.call(new Circle, new Rect); checkCollisionMDF.call(new Rect, new Circle); There is only one limitation: the MDF library has to have replicated code for each number of parameters of a MDF it wants to support, so the maximum number of parameters of the MDF function is arbitrarily limited. But other than that, (correct me If I'm wrong) isn't that usage as simple as possible, in fact, as simple as CLOS's multimethods? -- Bruno Medeiros - MSc in CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
Oct 18 2006