Of all the examples (in Perl 5 / Moose, Ruby, Javascript & Python) I think this one is the most clean and intuitive. Perl 6 has a good future if it keeps this up!

And it all went surprising smoothly. There were a couple of bumps in my Perl 6 road but these are all connected to the flux between the Perl 6 spec, Rakudo and knowing what info you find on the web is still accurate (or not).

First bump was how to re-open a class. Most Perl 6 documentation implied that classes were always open (unless is final was used). This no longer seemed to be the case and it gave examples of class A is augmented { ... }. However this didn’t work in Rakudo but eventually I came across is also which did.

I like the look of class A is also { ... }. However Moritz on IRC #perl6 mentioned that the Perl 6 spec had changed so my example would need to be:

Actually, the main reason for abandoning “is also” is that it turned the name lookup into a semantic pretzel retroactively. With the “augment” declarator out front, we already know when we’re parsing the class name that we will be looking up an existing name, not adding a new name. This simplifies the internal logic since we don’t have to change anything after the fact; we just do the correct lookup when we see the name. And this is important because, unlike in Perl 5, names are always introduced immediately, and can be referred to later in the same expression, so we need to poke them into the symbol table as soon as possible, without having to worry about having to “unpoke” them later. We can also issue name collision errors immediately, instead of having to remember to check later.

I suppose this is an example of a language being pulled between something beautifully linguistic as class Ninja is also {} compared to something more parser/compiler efficient as augment class Ninja {}.

Keep stirring that pot because Perl 6 seems to be fermenting into something really lovely.

Re: the add_method thing, the more mooselike way would be $object.HOW.add_method($object, ‘methname’, method { … }), with HOW being the Perl6 name for the meta-thing. The ^-syntax is a convenience shortcut for this that also passes the object itself along for metaclass methods that want it.

Funny enough I did know about HOW (and WHAT) and had also seen that ^ was use as a shortcut but they had all completely escaped my memory when I was looking and kept hitting docs with .meta method… probably because I was searching for “meta” 😦

Clearly the old Perl6 docs on the internet could be an issue going forward (in fact when I was on IRC that day mentioned in above post there was someone else hitting exactly same prob).

About…..

My name is Barry Walsh. I'm a freelance IT consultant from London, UK. [more]

This blog is mostly about Perl programming because this is what I use and love (and occasionally hate!) for the majority of my working (and sometimes non-working) day.

Occasionally I will touch on other subjects like PostgreSQL, Mac OSX, UNIX, Linux, Ruby, jQuery, Javascript, XML and many more techie things that I also play with regularly. Other non techie aspects of my life may slip in now and again but I'll try and keep that to a minimum because its normally boring anyway :)