How about "leave"?

leave 
     <SURROUNDING> | [<SURROUNDING>]<IDENTIFIER>
     [ [result] <VALUE-SPEC> ];

Aliases:
=========
return -> "leave sub"
exit   -> "leave program" (or is it "thread"?)
break  -> "leave loop" (this is shaky: does it deserve to be here?)
last   -> "leave block"

Extensions (these are WAY! optional):
==========================
enter $jb BLOCK;
leave $jb [result $val];

You may recognize these from a past life. But now they're like an
inversion of throw-catch/return, since the result is "left".




my $jb;

sub myoutersub()
{
  ...
  $val = enter $jb {
    mysub();
    ...
  } if $needwork;
  ...
  return $val;
}
  
sub mysub()
{
  OUTER: for ...
    for ...
      if $foo -> 
      {
        ...
        leave block if $bar;       # leaves the "if" block
        leave sub if $foo > 100;   # returns
        leave OUTER if is_prime($foo); # last OUTER if ...
      }

  leave $jb result 0   
    if $xyz;              # Back to myoutersub, leaves block
}

=Austin


--- Larry Wall <[EMAIL PROTECTED]> wrote:
> On 27 Oct 2002, Marco Baringer wrote:
> : why not use -> to create a sub which you can return from?
> : 
> : if $foo -> {
> :   ...
> :   return if $bar;
> :   ...
> : }
> 
> Except that by the current rule you can only C<return> from something
> that is declared with the word "sub".   ->{...} is still just a fancy
> block from that perspective.
> 
> : this of course means you can't directly return from the sub (or
> whatever) in
> : which the if (or given or while or for) is nested...
> 
> Which is why the rule for "return" says there has to be a "sub",
> because that's what people will usually expect "return" to do, at
> least
> until they get sophisticated about every block being a subroutine.
> And that's also why we need a different way of returning from the
> innermost block (or any labelled block).  "last" almost works, except
> it's specific to loops, at least in Perl 5 semantics.  I keep
> thinking
> of "ret" as a little "return", but that's mostly a placeholder in
> my mind.  I've got a lot of those...
> 
> : slightly related:
> : 
> : what happens to the return value of the subs passed to for, if,
> while
> : and given statements? (what does '$foo = if $bar { ... } else { ...
> }'
> : do?)
> 
> Same thing as in Perl 5.  Try this:
> 
>     print do { if (int rand 2) { "true" } else { "false" } }, "\n";
> 
> The only difference is that in Perl 6, there is no cat.  :-)
> 
> Larry
> 


__________________________________________________
Do you Yahoo!?
Y! Web Hosting - Let the expert host your web site
http://webhosting.yahoo.com/

Reply via email to