Re: The distinction between "do BLOCK while COND" and "EXPR while COND" should go

[email protected] (Tom Christiansen) Thu, 31 Aug 2000 11:21:26 -0600
Newsgroups perl.perl6.language.flow
Message-ID <11123.967742486@chthon>
>I want last, next, etc. to magically work where I want them to:

>  do {
>    last if /booger/;
>    ...
>  } while ( ... );

Special cased for postfix modifiers, or generalized?  If so,
what's the return value?

    $x = TERM OP  do  { BLOCK }  OP TERM;

Actually, these are all pretty similar in that regard:

    do   { BLOCK } 
    eval { BLOCK } 
    sub  { BLOCK } 

In that do{} and eval{} both do the same thing--run that code
now--but that eval{} traps exceptions.  sub{}, meanwhile, returns
a handle to that block for subsequence execution.   Or you could
say that eval{} and sub{} both do the same thing insofar as return
will exit either of them, but return does not work on do{}.

	    run when?		trap exceptions?  	exit via?

    do	      now		    no			  ---
    eval      now                  yes			  return
    sub      later                  no			  return 

Actually, you *can* last out of an eval{} or a sub{}, but only
in the case that they themselves had a real loop in dynamic scope.
It's not an immediate "return from this named block wherever I am",
though, as it depends on whether there are loops inside the sub and
whether there are any outside of it.

One could argue that do{} should take return so it might have a value,
but this will definitely annoy the C programmers.

--tom