Em Qui, 2009-03-05 às 18:43 -0800, Jon Lang escreveu:
> OK; let me get a quick clarification here.  How does:
>     say "Hello, World!";

This is the equivalent to

 &say.postcircumfix:<( )>( \("Hello, World") );

> differ from:
>     "Hello, World!".say;

This is just

  "Hello, World!".say;

Meaning, the first dispatch is private to the sub, the second to the
object.

> or:
>     say $*OUT: "Hello, World!";

  $*OUT.say("Hello, World!");

dispatch is private to $*OUT...

> And more generally, would there be a
> reasonable way to write a single routine (i.e., implementation) that
> could be invoked by a programmer's choice of these calling
> conventions, without redirects (i.e., code blocks devoted to the sole
> task of calling another code block)?

This is exactly what this change has enabled. Now it doesn't matter if
your signature had an invocant or not, if that code is available as a
method it can be dispatched as a method, if it is available as a sub, it
can be dispatched as a sub, which means that you can install a sub as a
method and a method as a sub, it doesn't mattter...

> Could you use binding?
>     my sub say (String *$first, String *...@rest, OStream :$out = $*OUT,
> OStream :$err = $*ERR)
>         { ... }
>     role String {
>         has &say:(String $first: String *...@rest, OStream :$out = $*OUT,
> OStream :$err = $*ERR)
>             := &OUTER::say;
>     }

semantically, yes... but I don't think there's a syntax to bind a sub as
a method... You need to do it through the meta api at this moment...

maybe we could have something in the lines of

  method bar ::= &bar;

or even

  method bar is external <&bar>;

daniel

Reply via email to