This is a p6 question, not an NQP question - I'm citing the NQP only
because it's my current example. So mentioning p6 features not currently
in NQP is totally appropriate.

What I mean by converting code into data is simply that a run-time
version of metaprogramming will generally translate the code:

  $some_object.foo_method();

into data:

  method foo_method() {
     self.do_something('foo');
  }

In this example, the call to "foo_method" turned into a different call,
with "foo" as a string(data) instead of a function.

A C version, using macros, might do something like:

  #define function_template(name) \
     void name () { return 1; }

  function_template(foo)

This, to me, is turning (compile-time) data into code. And because it is
a compile-time thing, and there's no extra overhead, it's as close to
the metal as I'm likely to get.

(Of course, using a template means that some possible tweak, based on
"this particular method never gets used to ... blah blah ...", might not
get made. But that's okay.)

I'm remembering a ".assuming" modifier from a while back. Maybe that's a
way to eliminate the extra step:

  &foo_method := &template_method.assuming($arg1 := 'foo');

Or is there a better way?

=Austin


Geoffrey Broadwell wrote:
I'm not entirely sure what you mean here by "translate code into data
(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





Reply via email to