On Wed, 2009-12-09 at 00:16 -0500, Austin Hastings wrote:
Geoffrey Broadwell wrote:
by name Perl 6 syntax:
$obj."$method_name"(...args...);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.
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 callI 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.
by name Perl 6 syntax:
$obj."$method_name"(...args...);
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.
(method name into string)". The method name is already a string, which
is why I offered the "call by name" syntax above. But of course if you
have a code object for the method itself, you could do this in Perl 6:
$obj.$method(...args...);
Sadly this does not currently work in NQP-rx, though IIUC there's no
reason it couldn't (and in fact I've already requested this feature
because it would be useful for some function table stuff I do).
Full Perl 6 offers a number of features that would be useful for calling
a whole pile of dynamically-chosen methods on an object, but few have
been implemented in NQP-rx. (I would assume because there hasn't been a
lot of demand for it yet.)
I'll let the Perl 6 gurus follow up with actual syntax examples for some
of these nifty features. ;-)
-'f