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

Perl6 and Duff's Device

Thread Next
From:
Gaal Yahas
Date:
March 20, 2005 10:41
Subject:
Perl6 and Duff's Device
Message ID:
20050320184034.GA18134@sike.forum2.org
It looks like Duff's Device <http://www.lysator.liu.se/c/duffs-device.html>
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 <gaal@forum2.org>
http://gaal.livejournal.com/

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About