If you’ve never used multiple dispatch, you’re in for a treat. We’ve had it working in Parrot for years, but Jonathan Worthington just added the basics of MMD support to Rakudo (Rakudo is an implementation of Perl 6).

Why do you want multiple dispatch? Here’s a clever little example:

class Thing             {}
class Rock     is Thing {}
class Paper    is Thing {}
class Scissors is Thing {}

multi sub defeats(Thing    $t1, Thing    $t2) { 0 };
multi sub defeats(Paper    $t1, Rock     $t2) { 1 };
multi sub defeats(Rock     $t1, Scissors $t2) { 1 };
multi sub defeats(Scissors $t1, Paper    $t2) { 1 };

my $paper = Paper.new;
my $rock  = Rock.new;

say defeats($paper, $rock);
say defeats($rock, $paper);

Download the new Parrot release next Tuesday, 15 April 2008, then type:

$ perl Configure.pl
$ make
$ make perl6

… and you too can play with this in your own code.

Update: Note that multiple dispatch is different from static signature-based overloading and pattern matching in that multiple dispatch works correctly even when you don’t know the specific types of the invocants at compile time. Imagine that I threw a rand() call in there, for example.