In a message dated Tue, 5 Sep 2006, Ph. Marek writes:
I now had a look at http://dev.perl.org/perl6/doc/design/syn/S06.html but didn't find what I meant. Sorry if I'm just dumb and don't understand you (or S06); I'll try to explain what I mean.

I don't think you're dumb; the Synopses just require that you intuit certain things from each other, from examples in other Synopses, and so on in a Perlish sort of way; what you're looking for is not spelled out explicitly. It can be found by noticing how you specify subtypes, along with noticing that subtypes can be specified as parameter types. There's also an example showing explicitly what you want in S12.

In Perl5 this looks like

        sub SomeThing
        {
          my($a, $b)[EMAIL PROTECTED];

          return b+2 if ($a == 4);
          return a+1 if ($b == 3);
          return a*b;
        }
[...]
What I am asking is whether there will be some multimethod dispatch depending
on the *value*, not the *type*, of parameters.
Perl6 could possibly do something with "given"; but matching on multiple
variables seems to be verbose, too.
I'm looking for something in the way of

        sub SomeThing(Num $a, Num $b) where $a==4 is $b+2;
        sub SomeThing(Num $a, Num $b) where $b==3 is $a+1;
        sub SomeThing(Num $a, Num $b) { return $a * $b }

It's just

   multi sub SomeThing(Num $a where {$^a == 4}, Num $b) { $b + 2  }
   multi sub SomeThing(Num $a, Num $b where {$^b == 3}) { $a + 1  }
   multi sub SomeThing(Num $a, Num $b)                  { $a * $b }

but without specifying the signature multiple times (or maybe we should, since
it's MMD). Now

Yes, the signatures are different--the first two multis specify subtypes as their signatures, the last specifies a canonical type.

Trey

Reply via email to