Today I have again failed to build Perl 6 on Solaris. Eventually I managed to get it to compile on an older Linux box. I figured a good place to check out basic functionality was to create a doubly-linked list class and see how easy it is. That's when I discovered a lot of problems just trying to find good examples of Perl 6 code on the Web. Where's a simple class with an object initializer? I think I write something like this:
class Node { has $.val is rw; has $.next; has $.prev; submethod BUILD ($self:) { $self.!linkto($self); } method !linkto ($self: Node $target) { $.next = $target; $target.prev($self); } }
Of course, that's just a stub class, but no matter how I try to write it, I always get a Statement not terminated properly at line 6, near "($self:) {\n" error. Maybe submethods aren't implemented, but I figured I could examine the spectests to see what's there and that's where the real problem kicks in: make spectest uses subversion to fetch the tests from the pugs repository. Our firewall doesn't allow this. I had planned to spend today working with Perl 6, but there are still too many obstacles for just casually playing around. It's getting so much closer I can just taste it, but not yet. Not yet. Damn!
Update: I give up. I've tried multiple workarounds just to get a proper Node constructor up and running and everything is throwing errors :(
I wonder what the solution with Method::Signature and Moose would look like.
Re:Method::Signatures / Moose solution
jplindstrom on 2008-10-30T23:12:58
I've' tried some of that, and it's mighty fine crack.
I believe submethods and private methods are currently unsupported. I can't find any submethods in the spectests, and I can get the code to parse if I remove "sub" and "!" appropriately.
Re:Unsupported
JonathanWorthington on 2008-11-02T15:35:07
I believe the "my method..." syntax for private methods works, but not the ! yet.