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

Re: SMD is for weenies

Thread Previous | Thread Next
Piers Cawley
July 6, 2005 04:58
Re: SMD is for weenies
Message ID:
Yuval Kogman <> writes:

> On Fri, Jul 01, 2005 at 13:42:34 +1200, Sam Vilain wrote:
>> Yuval Kogman wrote:
>> >As I understand it SMD is now not much more than a mechanism to
>> >place a constraint on the MMD, saying that there can only be one
>> >method or subroutine with the same short name.
>> >Why is this the default?
>> Otherwise you lose this quite useful warning if the signatures didn't
>> match;
>>     method foo redefined at ...
> That's a good point...
> I'm guessing that the default warnings should have a warning for MMD
> methods which append to a short name without appearing immediately
> after each other in the same file.
>> I agree with you MMD is very cool, and I use it a lot.  But I don't
>> mind clarifying the intent with "multi"; this "overloading" is
>> considered by some to be surprising to new programmers.
> Prepending 'mutli' is not a problem when I have to type it. It's a
> problem when others won't type it. When 90% of the module code I'll
> be using is not MMD compatible, because MMD is not the default, I
> can't specialize other people's code without editing it (at runtime
> or at the source level).
> Overloading won't happen unless people overloading semantics are
> introduced, and that's exactly what I'd like to do to other people's
> code occasionally.

Then write yourself a module, call it 'multiplicity' say, which would allow you
to say  

    use multiplicity;

    sub foo (...) {...} # foo is a multimethod, even if there's already a 'SMD'
                        # foo in existence.

It shouldn't even be that hard, just macroize sub/method/whatever to become
multis that first check if there's already a singly dispatched sub with the
same name and promoting to multi status if possible. 

Of course, if you use something like that, you're taking the risks on your own
head, but you knew that as soon as you typed 'use multiplicity'. 

The important thing is that the dispatch and reflection system should be
flexible enough to allow you to write something like this.

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