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.
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<foo>); $c.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!
User dug Read This (or, Cellular Automata for Kicks in 6) 0 Comments More | Login | Reply /