2009
07.15

There are a few corrections that were needed from my .WALK talk yesterday. Having the Rakudo pumpking sitting next to you makes answering questions much easier.

First, moritz_ strongly suggested I post working code and not off-the-cuff code anymore. His argument was that it further perpetuates the meme that Perl 6 is vapor. So here’s a properly working example:


class A {
    method baz { ... };
    method bar { ... };
};

class B is A {
    method baz { ... };
    method icanhaz { ... };
};

class C is B {
};

class D is A {
    method ucanhaz { ... };
};

my @candidates;
my C $c .= new;
@candidates = $c.WALK(:name<baz>);
say @candidates.map(*.name).join(', ');
@candidates = $c.WALK(:name<icanhaz>);
say @candidates.map(*.name).join(', ');

So the obvious correction there is the change to class. This is because modules cannot inherit. Also, the named parameters were supposed to use <> or quotes. The say calls were added to see the results immediately (aestetics).

Also, it seemed that in my attempt to understand WALK, I misread the entire intent of the returned results. The WALK iterator will in fact return callable methods (Code objects?). Those methods can then be called with the $* and $+ operators (as discussed in S12). The correct output is:


baz, baz
icanhaz

The two baz methods are B::baz and A::baz, while the icanhaz is just B::icanhaz. Since multi method dispatch never truely hides methods, similar to C++ (Base::method) and Java (super.method), A::baz is still available for dispatching.

Lastly, :name is not required, since it will return all methods. :name, hence why it was bundled in the filter parameter list, merely filters out method name matches.

That should wrap the loose ends. I hope the attendees enjoyed learning about method dispatch and WALK. I’m soliciting for next month’s talk if anyone wants to volunteer.

2 comments so far

Add Your Comment
  1. I’d love to do a talk at some point, but I have trouble learning about things I can’t find a use for. Maybe it would be a good idea to email some ideas of things to present on to the list?

  2. Then talk about the things you currently use and how they will work in Perl 6.

    Do you read files? Do you memory cache? Do you call functions or create objects? Think of all of those things you think of as CPAN modules and how they do the magic they do. Then translate them to Perl 6.

    There’s about a million things you could talk about (just think of how many Perl 5 books exist) from the things you already do.