Austin Hastings writes:
> > -----Original Message-----
> > From: Luke Palmer [mailto:[EMAIL PROTECTED]
> >
> > But this is already supported, in its most powerful form:
> > 
> >     wrap &block: { call; other_stuff() }
> 
> Hmm, no.
> 
> That does a call, which presumes a return, which burns up
> who-knows-how-many mips. Given that the compiler is being forced to
> remember the code in case someone overloads the semicolon operator, or
> whatever, I don't think it's unreasonable to catenate the .source
> values of various blocks, and that seems a reasonable behavior for
> <C>infix:.=(Block, Block) {...}</C>.

Oh... so that's the reason.  Well, you can give up hope on that, I'm
pretty sure.  If you want to do something like that, mess with the text
and eval yourself.

The reason is this:

    my &code := { 
        my $x = "Hello";
        print $x;
    }

    {
        my $x = "World";
        &code ~= { print $x }
    }

In any sane way of doing things, this should print HelloWorld.  That
means that your new appended block has to push the registers and load up
a new scratchpad just like any closure would.  The only thing you're
saving is a jump to the proper address, which is mostly negligible.

> Especially since the other way turns into:
> 
>   macro atexit(Block $b) {
>     get_the_current_sub().eval("my &block = {};")
>       unless defined &block;
>     wrap &block: { call; $b(); };
>   }

I really haven't the slightest idea what that's supposed to mean.

Where'd &block come from?  What does Code.eval(String) mean?

> Which makes two calls per additional whosit.
> 
> Frankly, I think I'd rather see:
> 
>   macro atexit($code) is parsed(/{ <Perl6.line>* }/) {
>     get_the_current_sub().eval("my $block;")
>       unless defined $block;
>     $block .= $code;
>   }
> 
>   macro return($retval) {
>     eval($block) if defined $block;
>     leave Routine, $retval;
>   }
> 
> But that imposes <C>eval()</C> pretty frequently. Better to provide some lower-level 
> hackish way to agglutinate Blocks.

And you suggest that this low-level hackish way is with a common
operator, like C<~>.  Oh, that's brilliant.

Luke

> 
> =Austin
>   
> 

Reply via email to