Damian Conway wrote:
> Any subroutine/function like C<if> that has a signature (parameter list)
> that ends in a C<&sub> argument can be parsed without the trailing
> semicolon. So C<if>'s signature is:
> 
>         sub if (bool $condition, &block);

So what does the signature for C<while> look like? I've been wondering about
this for a long time, and I've searched the Apocalypses and the
perl6-language archive for an answer, but I've had no success.

It seems like C<while>'s signature might be something like one of these:

      sub while (bool $test, &body);
      sub while (&test, &body);

But neither of these really works. 

The first would imply that the test is evaluated only once (and that once is
before 'sub while' is even called). That'd be useless.

The second would allow multiple evaluations of the test condition (since
it's a closure). But it seems that it would also require the test expression
to have curly braces around it. And possibly a comma between the test-block
and the body-block. That'd be ugly.

I can create a hypothetical "bareblock" rule that says:

      When an argument's declaration contains an ampersand sigil,
      then you can pass an "expression block" (i.e., a simple 
      expression w/o surrounding curlies) to that argument.

Is there such a rule for Perl 6? 

On the positive side, this would be an reasonable generalization of the Perl
5 handling of expressions given to map or grep. On the negative side, this
rule makes it impossible to have such arguments fulfilled by evaluating an
expression that returns the desired closure (i.e., the expression you type
as an argument isn't intended to be the block you pass, but rather it is
intended to generate the block you want to pass).

In summary: assuming Perl 6 allows user-defined while-ish structures, how
would it be done?

=thom
   "The rowboat glided gently across the lake, exactly like a bowling ball
wouldn't."

Reply via email to