A while back, I sent my little brother (user dug) some Perl 5 scripts that render simple cellular automata to a terminal. I thought he'd ignored me entirely until he publicly prodded me to see the Perl 6 versions I was (allegedly) working on.
Well, the module is checked into Pugs (Automata::Cellular), and here's a sample script:
use v6-alpha;
use Automata::Cellular;
my Automata::Cellular $ca .= new(:rule_number<30>);
say "Rule Number $ca.rule.rule_number()\n$ca.rule.pretty()\n$ca.prettystate()";
while ( $ca++ ) { say $ca.prettystate() }
1;
With output:
Rule Number 30
... becomes .
..x becomes x
.x. becomes x
.xx becomes x
x.. becomes x
x.x becomes .
xx. becomes .
xxx becomes .
Stage 1: ...............x...............
Stage 2: ..............xxx..............
Stage 3: .............xx..x.............
Stage 4: ............xx.xxxx............
Stage 5: ...........xx..x...x...........
Stage 6: ..........xx.xxxx.xxx..........
Stage 7: .........xx..x....x..x.........
Stage 8: ........xx.xxxx..xxxxxx........
Stage 9: .......xx..x...xxx.....x.......
I found the Perl 6 object model powerful, the interfaces easy to use. For example, I overloaded the "++" operator using a method like this:
method prefix:<++> {
## increment the state
}
Wow!
Adding an accessor to the class was even easier. I didn't even read any documentation- I just tried it, and it worked. Inside the class or role, just say something like:
has $.foo;
If you want something to type into Pugs, try this:
class a { has $.b }; my a $c .= new(:b
Yes, you really did just build a class called "a", create a new class a object, and use the "b" accessor. Wow.
So dug, now you know why I have become a citizen of Perl after ten years. Moose!