www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Multimethod library - mml.d

reply nail <nail_member pathlink.com> writes:
I know some time ago 'pragma' wrote multimethods lib, I used it but unfortunatly
found that it has bugs, has no feature to implicitly choose the best suitable
signature and not always was typesafe.

So I wrote my own, It supports unary and binary multimethods, and has no
mentioned drawbacks.

P.S: And nevertheless, I would very very happy if D begun to support mmethods
natively.

nail-mail <at> mail <dot> ru
begin 0644 mml.d
M+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O
M+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+R\O+PHO+PHO+R!-
M34P *&UU;'1I+6UE=&AO9"!L:6)R87)Y*2!I<R!I;7!L96UE;G1A=&EO;B!O
M9B!M=6QT:6UE=&AO9"!D:7-P871C:&EN9R!F;W(*+R\ 1"!,86YG=6%G90HO

M86MO<GEA:V]V("AN86EL+6UA:6Q`;6%I;"YR=2D*+R\*+R\ 5&AI<R!P<F]G
M<F%M(&ES(&9R964 <V]F='=A<F4[('EO=2!C86X <F5D:7-T<FEB=71E(&ET
M(&%N9"]O<B!M;V1I9GD :70 =6YD97(*+R\ =&AE('1E<FUS(&]F('1H92!'
M3E4 3&5S<V5R($=E;F5R86P ($QI8V5N<V4 87, <'5B;&ES:&5D(&)Y('1H
M92!&<F5E(%-O9G1W87)E"B\O($9O=6YD871I;VX[(&5I=&AE<B!V97)S:6]N

M=&5R"B\O('9E<G-I;VXN"B\O"B\O(%1H:7, <')O9W)A;2!I<R!D:7-T<FEB
M=71E9"!I;B!T:&4 :&]P92!T:&%T(&ET('=I;&P 8F4 =7-E9G5L+"!B=70 
M5TE42$]55`HO+R!!3ED 5T%24D%.5%D[('=I=&AO=70 979E;B!T:&4 :6UP

M+R!&3U( 02!005)424-53$%2(%!54E!/4T4N(%-E92!T:&4 1TY5($QE<W-E
M<B!'96YE<F%L("!,:6-E;G-E(&9O<B!M;W)E(&1E=&%I;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YI;G1E<F9A8V5S*0H)"0D)"0ES=6)M:71$96QE

M<W1S("L ,2D[" D)"0E]" D)"7T*"0D)" D)"7-U8FUI=$1E;&5G871E*&%R
M9S$N8VQA<W-I;F9O+"!A<F<R+F-L87-S:6YF;RP ,"P ,"D[" D)" D)"6EF
M(" A8F5S=$1E;&5G871E*0H)"0E[" D)"0ET:')O=R!N97< 06UB:6=U;W5S
M0V%L;$5X8V5P=&EO;B B3F\ <W5I=&%B;&4 8V]N=F5R<VEO;B!F;W5N9"!F
M;W( *"( ? H)"0D)"6%R9S$N8VQA<W-I;F9O+FYA;64 ?B`B+"`B('X 87)G
M,BYC;&%S<VEN9F\N;F%M92!^("(I(BD[" D)"7T*"0D)" D)"7)E='5R;B!B
M97-T1&5L96=A=&4H87)G,2P 87)G,BD[" D)?0I]" IU;FET=&5S=`I[" EI
M;G1E<F9A8V4 02![?0H)8VQA<W, 0B`Z($$ >WT*"6-L87-S($, .B!"('M]
M" EC;&%S<R!$(#H 0R![?0H)8VQA<W, 12![?0H)8VQA<W, 1B`Z($4L($$ 
M>WT*"0H)+R\ 5'EP92!H:65R87)C:'D *&YO9&5S(&UA<FME9"!W:71H(", 
M;65A;G, =V4 9&5F:6YE9"!M971H;V0*"2\O(&9O<B!T:&ES('1Y<&4 :6X 
M=6YA<GD ;75L=&EM971H;V0I" DO+PH)+R\ ("` ("` ("` ("` ("` ("` 
M("` ("` ("-!("`C10H)+R\ ("` ("` ("` ("` ("` ("` ("` ("` ("!\
M(%P ?`H)+R\ ("` ("` ("` ("` ("` ("` ("` ("` ("!"("` 1 H)+R\ 
M("` ("` ("` ("` ("` ("` ("` ("` ("!\(`H)+R\ ("` ("` ("` ("` 

M('P*"2\O("` ("` ("` ("` ("` ("` ("` ("` ("` 1`H)+R\*"0H)" DO
M+R!":6YA<GD <')O9'5C="!H:65R87)C:'D *&YO9&5S(&UA<FME9"!W:71H
M(", ;65A;G, =V4 9&5F:6YE9`H)+R\ ;65T:&]D(&9O<B!T:&ES('!A:7(I
M" DO+PH)+R\ ("` ("` ("` ("` ("` ("` ("` 7U]?7U]?(T%!7U]?7U]?
M("` ("` ("` ("` ("` ("` ("` ("` ("` ("` ("` ("` ("` ("` ("` 
M("` (`H)+R\ ("` ("` ("` ("` ("` ("` ("`O("` ("` +R` 7"` ("` 
M7"` ("` ("` ("` ("` ("` ("` ("` ("` ("` ("` ("` ("` ("` ("` 
M("` ("`*"2\O("` ("` ("` ("` ("` ("` ("`O("` ("-!0B` ("!"02` 
M("!<("` ("` ("` ("` ("` ("` ("` ("` ("`*"2\O("` ("` ("` ("` 
M("` ("` ("\ ("` ("\ (%P ("\ (%P ("` 7"` ("` ("` ("` ("` ("` 
M("` ("` ("` " DO+R` ("` ("` ("` ("` ("` ("\ ("` 04, ("` 0D( 
M("` 0T$ ("!<("` ("` ("` ("` ("` ("` ("` ("` ("` " DO+R` ("` 
M("` ("` ("` ("` +R` ("`O("!<("`O("!<("`O("!<("` 7"` ("` ("` 
M("` ("` ("` ("` ("` ("` (`H)+R\ ("` ("` ("` ("` ("` ('P (T%$

M("` (`H)+R\ ("` ("` ("` ("` ("` ('P ("` 7"` +R` 7"` +R` 7"` 
M+R` ("!\("` ("` ("` ("` ("` ("` ("` ("` ("` ("` ("` ("` ("` 

M0R` ("!$0B` ("` ?"` ("` ("` ("` ("` ("` ("` ("` ("` ("` ("` 
M("` ("` ("` ("` ("` ("`*"2\O("` ("` ("` ("` ("` ("!\("` ("` 
M(%P ("\ (%P ("\ ("` ("` ?"` ("` ("` ("` ("` ("` ("` ("` ("` 
M("` ("` ("` ("` ("` ("` ("` " DO+R` ("` ("` ("` ("` ("` ?"` 
M("` ("` 0T0 ("` 1$, ("` ("` ('P ("` ("` ("` ("` ("` ("` ("` 
M("` ("` ("` ("` ("` ("` ("` ("` " DO+R` ("` ("` ("` ("` ("` 
M?"` ("` ("` ("!<("`O("` ("` ("` ('P ("` ("` ("` ("` ("` ("` 
M("` ("` ("` ("` ("` ("` ("` ("` " DO+R` ("` ("` ("` ("` ("` 
M?"` ("` ("` ("` 1$0 ("` ("` ("` ('P ("` ("` ("` ("` ("` ("` 
M("` ("` ("` ("` ("` ("` ("` ("` " DO+R` ("` ("` ("` ("` ("` 
M?"` ("` ("` ("` ("` ("` ("` ("` ('P*"2\O("` ("` ("` ("` ("` 
M("` 7"` ("!!12` ("-%12` ("-%02` ("`O" DO+R` ("` ("` ("` ("` 
M("` ("!<("`O("` ("`O("!<("` ("!<("`O(`H)+R\ ("` ("` ("` ("` 
M("` ("` ($%&("` (T5&("` ($9%("` ($9!("`*"2\O("` ("` ("` ("` 
M("` ("` ("` (%P ("` (%P ("\ ("` ("\ ("` " DO+R` ("` ("` ("` 
M("` ("` ("` ("` 7%]?7U]?1D9?7U]?7R\ ("` (`H)+R\*"0H)8VQA<W, 
M5&5S=&5R" E[" D)8VAA<EM=(&9O;RA!(&QH<RP 02!R:',I" D)>PH)"0ER
M971U<FX (D%!(CL*"0E]" D)" D)8VAA<EM=(&9O;RA!(&QH<RP 0B!R:',I
M" D)>PH)"0ER971U<FX (D%"(CL*"0E]" D)" D)8VAA<EM=(&9O;RA!(&QH
M<RP 1"!R:',I" D)>PH)"0ER971U<FX (D%$(CL*"0E]" D)" D)8VAA<EM=


M(CL*"0E]" D)" D)8VAA<EM=(&9O;RA%(&QH<RP 12!R:',I" D)>PH)"0ER
M971U<FX (D5%(CL*"0E]" D)" D)8VAA<EM=(&9O;RA%(&QH<RP 1B!R:',I
M" D)>PH)"0ER971U<FX (D5&(CL*"0E]" D)" D)8VAA<EM=(&9O;RA%(&QH
M<RP 02!R:',I" D)>PH)"0ER971U<FX (D5!(CL*"0E]" D)" D)8VAA<EM=
M(&)A<BA!(' I" D)>PH)"0ER971U<FX (D$B.PH)"7T*"0D*"0EC:&%R6UT 
M8F%R*$, >"D*"0E[" D)"7)E='5R;B`B0R([" D)?0H)"0H)"6-H87);72!B
M87(H12!X*0H)"7L*"0D)<F5T=7)N(")%(CL*"0E]" E]" D*"51E<W1E<B!T
M(#T ;F5W(%1E<W1E<B I.PH)" EA;&EA<R!":6YA<GE-=6QT:6UE=&AO9"$H
M8VAA<EM=*2!"34T[" E"34T 9F]O(#T ;F5W($)-32 I.PH)0DU-+D)E:&%V
M:6]U<B!B8F5H(#T ;F5W($)-32Y"96AA=FEO=7(H*3L*"6)B96  ?CT ;F5W
M($)-32Y$96QE9V%T92$H02P 02DH)G0N9F]O*3L*"6)B96  ?CT ;F5W($)-
M32Y$96QE9V%T92$H02P 0BDH)G0N9F]O*3L*"6)B96  ?CT ;F5W($)-32Y$
M96QE9V%T92$H02P 1"DH)G0N9F]O*3L*"6)B96  ?CT ;F5W($)-32Y$96QE
M9V%T92$H0BP 0RDH)G0N9F]O*3L*"6)B96  ?CT ;F5W($)-32Y$96QE9V%T
M92$H0RP 0RDH)G0N9F]O*3L*"6)B96  ?CT ;F5W($)-32Y$96QE9V%T92$H
M12P 12DH)G0N9F]O*3L*"6)B96  ?CT ;F5W($)-32Y$96QE9V%T92$H12P 
M1BDH)G0N9F]O*3L*"6)B96  ?CT ;F5W($)-32Y$96QE9V%T92$H12P 02DH
M)G0N9F]O*3L*"69O;RYI;FET:6%L:7IE*&)B96 I.PH)" EA;&EA<R!5;F%R
M>4UU;'1I;65T:&]D(2AC:&%R6UTI(%5-33L*"55-32!B87( /2!N97< 54U-
M*"D[" E534TN0F5H879I;W5R('5B96  /2!N97< 54U-+D)E:&%V:6]U<B I
M.PH)=6)E:"!^/2!N97< 54U-+D1E;&5G871E(2A!*2 F="YB87(I.PH)=6)E

M97< 54U-+D1E;&5G871E(2A%*2 F="YB87(I.PH)8F%R+FEN:71I86QI>F4H
M=6)E:"D[" D*"4( 8B`](&YE=R!"*"D[" E"(&, /2!N97< 0R I.PH)0B!D
M(#T ;F5W($0H*3L*"44 92`](&YE=R!%*"D[" E%(&8 /2!N97< 1B I.PH)
M" DO+R!B:6YA<GD ;65T:&]D<R!T97-T" EA<W-E<G0H(&9O;RAC+"!C*2`]
M/2`B0T,B("D[" EA<W-E<G0H(&9O;RAB+"!B*2`]/2`B04(B("D[" EA<W-E
M<G0H(&9O;RAD+"!C*2`]/2`B0T,B("D[" EA<W-E<G0H(&9O;RAF+"!E*2`]
M/2`B144B("D[" EA<W-E<G0H(&9O;RAE+"!F*2`]/2`B148B("D[" EA<W-E
M<G0H(&9O;RAF+"!F*2`]/2`B148B("D[" D)" ET<GD*"7L*"0EF;V\H8BP 

M17AC97!T:6]N(&4I" E[" D)87-S97)T*'1R=64I.PH)?0H)" DO+R!U;F%R
M>2!M971H;V1S('1E<W0*"6%S<V5R="  8F%R*&,I(#T
M97)T*"!B87(H9"D /3T (D,B("D[" EA<W-E<G0H(&)A<BAB*2`]/2`B02( 
M*3L*"6%S<V5R="  8F%R*&4I(#T](")%(B`I.PH)" ET<GD*"7L*"0EB87(H

E17AC97!T:6]N(&4I" E[" D)87-S97)T*'1R=64I.PH)?0I]"G5O
`
end
Feb 08 2005
next sibling parent "Craig Black" <cblack ara.com> writes:
I agree, multimethods are a very useful and powerful language feature.  They 
should be added to D.

"nail" <nail_member pathlink.com> wrote in message 
news:cuapgb$2ubv$1 digitaldaemon.com...
I know some time ago 'pragma' wrote multimethods lib, I used it but 
unfortunatly
 found that it has bugs, has no feature to implicitly choose the best 
 suitable
 signature and not always was typesafe.

 So I wrote my own, It supports unary and binary multimethods, and has no
 mentioned drawbacks.

 P.S: And nevertheless, I would very very happy if D begun to support 
 mmethods
 natively.

 nail-mail <at> mail <dot> ru
 
Feb 08 2005
prev sibling next sibling parent reply Norbert Nemec <Norbert Nemec-online.de> writes:
I have no experience with using multimethods. Looking at your
implementation, though, I have the feeling that this is an even more
complex issue than multiple inheritance and I doubt whether it is a good
idea to move it into the language.

Multimethods are not very efficient by principle. Even a native
implementation in the compiler will not change that. If there are other
details why you think a native implementation could do better than a
library-based one, it might be an idea to identify these points and try to
find ways to expand the language such that library-based multimethods can
be implemented better.




nail wrote:

 I know some time ago 'pragma' wrote multimethods lib, I used it but
 unfortunatly found that it has bugs, has no feature to implicitly choose
 the best suitable signature and not always was typesafe.
 
 So I wrote my own, It supports unary and binary multimethods, and has no
 mentioned drawbacks.
 
 P.S: And nevertheless, I would very very happy if D begun to support
 mmethods natively.
 
 nail-mail <at> mail <dot> ru
Feb 09 2005
next sibling parent nail <nail_member pathlink.com> writes:
In article <cucij7$1sa3$1 digitaldaemon.com>, Norbert Nemec says...
I have no experience with using multimethods. Looking at your
implementation, though, I have the feeling that this is an even more
complex issue than multiple inheritance and I doubt whether it is a good
idea to move it into the language.

Multimethods are not very efficient by principle. Even a native
implementation in the compiler will not change that. If there are other
details why you think a native implementation could do better than a
library-based one, it might be an idea to identify these points and try to
find ways to expand the language such that library-based multimethods can
be implemented better.
First - dispatch table will be built at compile time. Second - compiler can ignore type checking in the places where it is obvious, i.e. cast(XXX) is similar dynamic_cast in C++, but there are some often called places in my implementation where I'm sure that my Object reference is realy XXX subclass reference, that places can be rewrited to static_cast. Third - compiler can automaticly index classes at compile-time. This topic was rised some time ago, but Walter refuse flatly buitin multimethods as I remember. nail-mail<at>mail<dot>ru
Feb 09 2005
prev sibling parent reply "Craig Black" <cblack ara.com> writes:
 Multimethods are not very efficient by principle. Even a native
 implementation in the compiler will not change that.
You have no experience using multimethods, so how can you make such a rash statement about them? I DO have experience with them and they are very efficient if implemented correctly. They certainly can outperform the alternative, double dispatch. There are efficient ways to ensure a low memory footprint and an O(1) invokation. There has been much academic consideration of multimethods, but the average programmer doesn't know that they exist, let alone how powerful they are, so they are neglected. This is true of many programming paradigms. -Craig "Norbert Nemec" <Norbert Nemec-online.de> wrote in message news:cucij7$1sa3$1 digitaldaemon.com...
I have no experience with using multimethods. Looking at your
 implementation, though, I have the feeling that this is an even more
 complex issue than multiple inheritance and I doubt whether it is a good
 idea to move it into the language.
If there are other
 details why you think a native implementation could do better than a
 library-based one, it might be an idea to identify these points and try to
 find ways to expand the language such that library-based multimethods can
 be implemented better.




 nail wrote:

 I know some time ago 'pragma' wrote multimethods lib, I used it but
 unfortunatly found that it has bugs, has no feature to implicitly choose
 the best suitable signature and not always was typesafe.

 So I wrote my own, It supports unary and binary multimethods, and has no
 mentioned drawbacks.

 P.S: And nevertheless, I would very very happy if D begun to support
 mmethods natively.

 nail-mail <at> mail <dot> ru
Feb 09 2005
parent reply Norbert Nemec <Norbert Nemec-online.de> writes:
Craig Black wrote:

 Multimethods are not very efficient by principle. Even a native
 implementation in the compiler will not change that.
You have no experience using multimethods, so how can you make such a rash statement about them? I DO have experience with them and they are very efficient if implemented correctly. They certainly can outperform the alternative, double dispatch. There are efficient ways to ensure a low memory footprint and an O(1) invokation.
OK, sorry - I have rather strict criteria when talking about 'efficient'. Of course, efficiency always depends on the kind of problem you want to solve. If the problem inherently demands multi-dispatch, then it is certainly more efficient to have it built into the compiler than to do it 'by hand'. What I meant, is that you generally need to do some kind of a lookup at runtime. You say that this can be done O(1) - if that is indeed possible, it might change my view of the issue. As far as I can see, multi-dispatch will always need some lookup in a table. You may be able to implement this by using a btree or a hash-table, but neither of them is strictly O(1). Single-dispatch can simply be done by dereferencing a single pointer. This is still less efficient than static calls (especially on modern architectures, where it severely breaks branch prediction) but it is strictly O(1) with next to no overhead. For multi-dispatch, I cannot see any way to do that. If you have any pointers about it, I would personally be very interested. As for the design of D: it clearly is a difficult decision which features a language should support. Every programmer has some favorite programming style that depends on certain features in the language. Supporting everything is impossible and would lead to a cluttered language. Whether multimethods are important enough to include them is a matter of investigation. In any case, I would really want to see some real-world example that inherently depends on multimethods.
 There has been much academic 
 consideration of multimethods, but the average programmer doesn't know
 that
 they exist, let alone how powerful they are, so they are neglected.  This
 is true of many programming paradigms.
I can only fully support this statement.
Feb 10 2005
next sibling parent nail <nail_member pathlink.com> writes:
In article <cuf58k$1b8b$1 digitaldaemon.com>, Norbert Nemec says...
Craig Black wrote:

 Multimethods are not very efficient by principle. Even a native
 implementation in the compiler will not change that.
You have no experience using multimethods, so how can you make such a rash statement about them? I DO have experience with them and they are very efficient if implemented correctly. They certainly can outperform the alternative, double dispatch. There are efficient ways to ensure a low memory footprint and an O(1) invokation.
OK, sorry - I have rather strict criteria when talking about 'efficient'. Of course, efficiency always depends on the kind of problem you want to solve. If the problem inherently demands multi-dispatch, then it is certainly more efficient to have it built into the compiler than to do it 'by hand'.
Also, the bonus is elegant simple syntax for mm defenition.
What I meant, is that you generally need to do some kind of a lookup at
runtime. You say that this can be done O(1) - if that is indeed possible,
it might change my view of the issue. As far as I can see, multi-dispatch
will always need some lookup in a table. You may be able to implement this
by using a btree or a hash-table, but neither of them is strictly O(1).

Single-dispatch can simply be done by dereferencing a single pointer. This
is still less efficient than static calls (especially on modern
architectures, where it severely breaks branch prediction) but it is
strictly O(1) with next to no overhead.

For multi-dispatch, I cannot see any way to do that. If you have any
pointers about it, I would personally be very interested.
The best method for multi-dispatching I seen is multi-row displacement(matching). My library to some extent use ideas from it, but I couldn't implement it completely, 'cause it must be done within compiler. Read more at http://www.ifs.uni-linz.ac.at/~ecoop/cd/papers/1628/16280304.pdf. Alghorithm implemented on compiler side make binary multimethod call equivalent by time penalty to two virtual calls, triary to 4 virtual calls, n-ary to 2^(n-1) virtual calls, not bad.
As for the design of D: it clearly is a difficult decision which features a
language should support. Every programmer has some favorite programming
style that depends on certain features in the language. Supporting
everything is impossible and would lead to a cluttered language. Whether
multimethods are important enough to include them is a matter of
investigation. In any case, I would really want to see some real-world
example that inherently depends on multimethods. 
I'm work in gamedevelopment industry and here there are a LOT of examples. Consider collision-detection: how beautiful will be if to compute collision point between two physical primitives using compact syntax of multimethods, not using annoying visitor pattern. Or another example: class RenderInstruction {} abstract class RenderSystem { void apply(RenderInstruction ins); } class Mesh : RenderInstruction {...} class MeshVB : RenderInstruction {...} class MeshIB : RenderInstruction {...} class D3DRenderSystem : RenderSystem { void apply(RenderInstruction ins); void apply(Mesh ins); void apply(MeshVB ins); void apply(MeshIB ins); } class NURBSSurface : RenderInstruction {...} class SomeNURBSRenderSystem : RenderSystem { void apply(RenderInstruction ins); void apply(NURBSSurface ins); } class SomeAnotherWayToDescribeShape : RenderInstruction {...} class SomeNotYetExistentRenderSystem : RenderSystem { void apply(RenderInstruction ins); void apply(SomeAnotherWayToDescribeShape ins); } I can store reference to RenderSystem wich actualy can be any and call apply with any RenderInstruction derived argument. Concrete render system will self make decision what to do whith this instruction. This architecture allows to add new render systems (even with absolutely another paradigm) without RenderSystem class changes. Of course this exaples can be solved without multimethods, but any problem can be solved without OOP at all. So the question is about readability and code maintenance.
 There has been much academic 
 consideration of multimethods, but the average programmer doesn't know
 that
 they exist, let alone how powerful they are, so they are neglected.  This
 is true of many programming paradigms.
I can only fully support this statement.
Victor Nakoryakov nail-mail<at>mail<dot>ru
Feb 10 2005
prev sibling parent "Craig Black" <cblack ara.com> writes:
 For multi-dispatch, I cannot see any way to do that. If you have any
 pointers about it, I would personally be very interested.
I am currently developing a simulation engine for DoD modeling and simulations. The simulation engine uses a template for two dimensional multimethods. The multimethods are used to describe relationships between different kinds of objects in the simulation. It requires that each type be enumerated. This is difficult to do using C++ RTTI, so I use my own type system. Once each type is enumerated, O(1) algorithms are possible. The simplest way to do this is with an N-Dimensional array of methods. Since each type's enumerated value will be its index into the array. Each multimethod must have its own array. The number of dimensions will correspond to the number of virtual parameters. It is easy to see why this method is so fast. It is simply indexing a lookup table. The problem is that these arrays can become considerably large, especially as the number of virtual parameters increases. For this reason, my currently implementation is limited to two dimensions. However, there are algorithms that compress the lookup tables and still retain the O(1) performance. The drawback is that this approach is considerably more complex and difficult to implement.
 As for the design of D: it clearly is a difficult decision which features 
 a
 language should support. Every programmer has some favorite programming
 style that depends on certain features in the language. Supporting
 everything is impossible and would lead to a cluttered language. Whether
 multimethods are important enough to include them is a matter of
 investigation. In any case, I would really want to see some real-world
 example that inherently depends on multimethods.
Well my vote is to include multimethods natively. I suppose that a first step to providing high-performance multimethods in D is providing enumeration values for the types. They would have to be enumerated from each base class. Thus if B inherits A and C inherits B, C would have two enumerations: one with base A and another with base B. (If I'm confusing you just let me know and I will expound some more.) This would allow for high-performance multimethod libraries to be written. The next step would be to add the keywords and syntax sugar that replaces those libraries. -Craig
Feb 10 2005
prev sibling parent reply Mark Junker <mjscod gmx.de> writes:
nail schrieb:
 I know some time ago 'pragma' wrote multimethods lib, I used it but
unfortunatly
 found that it has bugs, has no feature to implicitly choose the best suitable
 signature and not always was typesafe.
What are multimethods? Regards, Mark
Feb 09 2005
next sibling parent nail <nail_member pathlink.com> writes:
What are multimethods?
Realization of so called late type binding. So if you have class A {} class B : A {} void foo(A u, A v) {...}; void foo(B u, B v) {...}; void main() { A b = new B(); foo(b, b); // foo(A, A) will be called } Multimethods is mechanism to redirect call to more suitable foo(B, B). To learn more google it. nail-mail<at>mail<dot>ru
Feb 09 2005
prev sibling parent "Craig Black" <cblack ara.com> writes:
 What are multimethods?
Virtual methods could be considered to be a special case of multimethod. A virtual method is similar to a one-dimensional multimethod where "this" pointer is the virtual parameter. Multimethods are essentially methods with one or more virtual parameters. However, unlike virtual methods multimethods are not members of a particular class. Instead, they define relationships between classes. I like to use the term "object-relational paradigm" to describe multimethods. Here is an example where multimethods describe the relationship between simple shapes. This syntax uses the virtual keyword to denote a virtual parameter. class Shape { ... } class Triangle : Shape { ... } class Rectangle : Shape { ... } class Circle : Shape { ... } bool overlap(virtual Shape *a, virtual Shape *b) = 0; bool overlap(virtual Triangle *a, virtual Rectangle *b) { ... } bool overlap(virtual Rectangle *a, virtual Circle *b) { ... } bool overlap(virtual Triangle *a, virtual Circle *b) { ... } Then if you have two shape pointers, just invoke the overlap method and the appropriate overload will be called. Shape *a = new Triangle(...); Shape *b = new Circle(...); overlap(a, b); -Craig
Feb 09 2005