develooper Front page | perl.perl6.language | Postings from March 2005

Re: MMD as an object.

Thread Previous | Thread Next
Thomas Sandlaß
March 9, 2005 03:26
Re: MMD as an object.
Message ID:
Rod Adams wrote:
> It seems to me that there are several advantages to making a group of 
> multi with the same short name a single object, of type 
> MultiSub|MultiMethod, which internally holds references to the all the 
> various routines that share that short name.

It doesn't have to be junctive because for a multi it's irrelevant
if it's a method or a sub. This distinction is used only at compile
time of the class closure. So I guess there is a

class Multi is Code {...}

in Perl 6.

> It would behave like a tied sub (or method), with a .dispatch method to 
> decide which of the contained routines should be called this particular 
> time. Manhattan would be the default. However, one can override the 
> dispatch logic; implementing Luke's Patterns idea, for example.

I see. Something like

use MMD::Manhattan;
use MMD::Symmetric;
use MMD::Pattern;

 > [..] I don't think there has
> been syntax introduced thus far that enables this ability. But it's 
> likely I missed it along the way, like I seem to be missing several 
> other things lately.

I interpret the hash like syntax &foo<Int,Array[Int]> such that
&foo represents the complete set of branches of multi sub foo.
The only thing I wonder is this also supported for calling particular
subs without dispatching: foo<Int>(17)? Or even partial dispatching
on the sliced multi? This would BTW be something the optimizer would
use as well.

> Another thing I haven't seen is how to declare a new multi at runtime. 
> Non-multi's can be created via C< &func := sub {...}; >, but that's 
> destructive to any other routines that might have occupied that 
> namespace.

If the above is correct than it would be more like hash assignment.

> There are likely several rough edges in here, and I've by no means 
> convinced myself that this is the Right Thing, but I thought I'd throw 
> the idea out there to what others thought of it.

I see some convergence and choices where that is not the case.

TSa (Thomas Sandlaß)

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About