On Tue, 2005-04-26 at 09:49, Juerd wrote:

> >                     return $self but role {
>     does role { ... }

As I understood (please correct me if I'm wrong), the difference between
"does" and "but" was that does modifies the existing object in-place,
and does creates a copy with the new mixin functionality. In this case,
the method in question is acting as a generator, and should NOT modify
the invocant.

I'm getting this from S12:

        Then you can say
            $a = 0 but answer(42)
        Note that the parenthesized form is not a subroutine or method
        call. It's just special initializing syntax for roles that
        contain a single property. The above really means something
            $a = ($anonymous = 0) does answer(42);
        which really means:
            (($anonymous = 0) does answer).answer = 42;
            $a = $anonymous;
        Which is why there's a but operator.

> > It certainly seems very attractive, but I'm not sure if roles can be
> > anonymous and/or closures.
> They can. But I think what you wrote is rather unnecessarily complex.

How is this complex? This is fairly standard for a factory type method
(I think I said "generator" before, oops), but in most languages, a
factory either has to return from a pre-defined tree of classes, or has
to build its own mechanism. In Perl 6, closures combined with anonymous
roles let us build this functionality trivially, on the fly.

Aaron Sherman <[EMAIL PROTECTED]>
Senior Systems Engineer and Toolsmith
"It's the sound of a satellite saying, 'get me down!'" -Shriekback

Reply via email to