> @@ -264,17 +264,34 @@
>  The C<.next> and C<.last> methods take an optional argument giving
>  the final value of that loop iteration.  So the old C<next LINE>
>  syntax is still allowed but is really short for C<next LINE:> using
> -indirect object syntax.
> +indirect object syntax.  Any block object can be used, not just labels,
> +so to return a value from this iteration of the current block you can say:
> +
> +    &?BLOCK.next($retval);

Would this work for 'break'?  In particular, do we need something to
the effect of &?TOPIC in order to indicate the block that 'break'
causes you to leave?

> +[Conjecuture: a bare C<next($retval)> function could be taught to do
> +the same, as long as C<$retval> isn't a loop label.  Presumably multiple
> +dispatch could sort this out.]

Also, since positional parameters can be used as named parameters (I
think), you could make the distinction between LABEL.next and
next($retval) explicit if you ever encounter a situation where you
need to return a label:

  next :return(LABEL) # passes LABEL as return value
  next LABEL # loops to next iteration of LABEL

> +Since the final expression in a subroutine returns its value, it's
> +possible to accidentally return a loop's return value when you were
> +only evaluating the loop for its side effects.  If you do not wish
>  to accidentally return a list from the final loop statement in a
>  subroutine, place an explicit return statement after it, or declare
>  a return type of C<Void>.

With the advent of return values for next and last, you might also
handle this by explicitly ending the loop with a 'next' that does not
return a value.  Question: should this be the default behavior for the
statement 'next;', or should the programmer have to explicitly
indicate that nothing is being returned (e.g., 'next void;')?

-- 
Jonathan "Dataweaver" Lang

Reply via email to