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

Perl6 and Duff's Device

Thread Next
Gaal Yahas
March 20, 2005 10:41
Perl6 and Duff's Device
Message ID:
It looks like Duff's Device <>
won't be possible in Perl6. This is a shame.

     sub duff ($from) {
         # real life would use reference here, this is a demo
         # dummy: simulate write to serial i/o port
         my $to;
         my $i = 0;
         my ($n, $count);
         $count = $from.chars;
         $n = ($count + 7) / 8; # use integer in effect
         %MY::«{"l" ~ $count % 8}».goto();
         l0: do {    $to ~= (substr $from, $i++, 1);
         l7:         $to ~= (substr $from, $i++, 1);
         l6:         $to ~= (substr $from, $i++, 1);
         l5:         $to ~= (substr $from, $i++, 1);
         l4:         $to ~= (substr $from, $i++, 1);
         l3:         $to ~= (substr $from, $i++, 1);
         l2:         $to ~= (substr $from, $i++, 1);
         l1:         $to ~= (substr $from, $i++, 1);
             } while (--$n>0);
         return $to;

In Pugs at least, labels may only only be assigned to blocks. Any chance
the language gets to have them in more arbitrary places? Would this in
fact be enough to make this work?

Gaal Yahas <>

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