Jarkko Hietaniemi wrote:
> 
> Allow me to repeat: instead of trying to shoehorn (or piledrive) new
> semantics onto existing keywords/syntax, let's create something new.
> The blocks of grep/map/... are special.  They are not quite looping
> blocks, they are not quite sub blocks, they are different.  Well, to
> be frank they are just very plain, ordinary, blocks that return their
> last value, but if we want to introduce both flow control

So, why not get rid of the specialness? Why can't all blocks return
their last value? The ones that currently do not return a value would
just be given void context. (Just because there's nowhere for the value
to go doesn't mean they can't return a value.) And if that's done, then

$val = 1;
$fact = while ($n) { $val *= $n--; } || $val;

might not be a horrible idea either.

Then we would have sub BLOCKs and loop BLOCKs. 'return' would escape the
nearest enclosing sub BLOCK and return a value. last/redo/next would
escape/repeat/continue the enclosing BLOCK of any sort, and would be
extended to specify the value returned. 'last $value' would be
equivalent to 'return $value' inside a subroutine unless it were
enclosed in a loop BLOCK.

Extension idea: just use last LABEL, $value:

last LABEL => $value
or
last => $value

(last, $value seems like it wouldn't be terribly useful otherwise,
right?)

Oh yeah. do BLOCK is still a third kind, which is transparent to all
control constructs.

What am I missing?

Reply via email to