Geoffrey Broadwell wrote:
On Tue, 2009-12-08 at 18:58 -0500, Austin Hastings wrote:
I know that I could 'metaprogram' this stuff by using string manipulation on the various method names, and then calling a (self-built) call_method($obj, $method_name, ...args...) function.

You don't need to write this by hand.  NQP-rx supports the method call
by name Perl 6 syntax:


which makes this kind of thing much easier.  I use it in Plumage in a
number of places.

But I'm curious if there's some P6 feature I've forgotten about (which I've forgotten most of them, excepting the rev number) that would let me do this without having to go too far away from the metal.

The above syntax is actually pretty close to the metal because it
translates directly to standard PIR ops.

The problem I have with the above is that it seems to require a second layer of call. Something like:

sub beforeall_methods() { return fetch_methods_by_category('beforeall'); }

   sub fetch_methods_by_category($cat) {...}

Essentially, it's one level of function call to translate code into data (method name into string) and then the "template" function is the second layer of call.

I'm not (believe it or not) actually trying to solve a problem here, so much as I am trying to learn what kind of features p6 offers for this using a concrete example.

Coming at this from a different angle, C# offers syntactic sugar for getter/setter methods. This example of mine might be a candidate for a macro, depending on the language. But is this a p6 macro? Or is there some in-between that I just don't know about.


Reply via email to