On Thu, Jul 07, 2005 at 06:37:58PM +0800, Autrijus Tang wrote:
: * A closure form of `but` is desugared into a `do given` block that
:   eliminates the need of returning $_ explicitly.  So those two forms
:   are equivalent:
: 
:     my $foo = Cls.new but {
:         .attr = 1;
:     };
: 
:     my $foo = do given Cls.new {
:         .attr = 1;
:         $_;
:     };

I just noticed that our rewrite doesn't quite work unless you rewrite
every "when" clause in the first form to also return $_, since "when"
blocks would escape past the return of the $_.  Any form of "leave"
could have the same problem.  I think the proper semantics of "but"
are that it ignores any return value however generated and pretends
the topic was returned.  In fact, the original closure should probably
be evaluated in void context.  So it's doing something more complicated
like:

    my $foo = do given Cls.new {
            given $_ {
                .attr = 1;
            }
            $_;
        }
    };

But hey, that just makes the monkey-but sugar seem all the sweeter.  :P

Larry

Reply via email to