Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

JonathanWorthington (6049)

JonathanWorthington
  (email not shown publicly)
http://www.jnthn.net/
Wednesday December 10, 2008
06:22 PM

;; works, making illegal things illegal

[ #38063 ]

Today I have done a couple more things on multiple dispatch in Perl 6. The major one is that ;; now works (it's been parsed for a while, but now it has the expected effects). The idea is that you put ;; in a signature in place of a comma to separate two parameters. Any paramters after this are not considered by the multi-dispatcher. For example, the following two multis:

multi foo(Int $a, Num $b) { 1 }
multi foo(Num $a, Int $b) { 2 }

Will, when invoked as foo(1,1), give an ambiguous dispatch error, since neither of these subs is narrower than the other - they are tied. However, if you instead wrote:

multi foo(Int $a;; Num $b) { 1 }
multi foo(Num $a;; Int $b) { 2 }

Then foo(1,1) will call the first of these multis, since it only looks at the signatures so far as the ;; and Int is a narrower type than Num, so the bit of the signature it cares about is narrower, so the ambiguity is gone. Of course, foo(1, "x") will fail because while the multi-dispatcher doesn't care about the second parameter, you still have to meet its signature requirements.

The more minor one is that multi, only and proto may only be used, according to the spec, on named routines, not anonymous ones. Rakudo now meets this bit of the spec (it will give a compile time error), and I've put in some spec tests to check this too.

And with these two additions, the grant from Deep Text draws to an end. I'll be posting a final report soon - thanks to Deep Text for funding this, and many other bits of, hacking on Rakudo's multiple dispatch! :-)

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.