John M. Dlugosz 提到:

> But about your answer, "automatically called with no arguments". Isn't
> that what a bare closure normally does anyway? Say, I introduced extra
> {} just for scoping or naming the block, where a statement is expected.
> 
> foo;
> bar;
> { my $temp= foo; bar(temp); } #forget about $temp.

Correct, but a pointy "-> $i {...}" is not bare, and neither is blocks
with placeholders such as "{ $^i }".

In fact, the latter is currently an error in Pugs:

$ ./pugs -e '{$^i}'
*** Blocks with implicit params cannot occur at statement level
    at -e line 1, column 1

The relevant paragraph is S04/"The do-once loop":

"
Although a bare block is no longer a do-once loop, it still executes
immediately as in Perl 5, as if it were immediately dereferenced with
a C<.()> postfix, so within such a block C<CALLER::> refers to the
scope surrounding the block.  If you wish to return a closure from a
function, you must use an explicit prefix such as C<return> or C<sub>
or C<< -> >>.  (Use of a placeholder parameter is deemed insufficiently
explicit because it's not out front where it can be seen.  You can, of
course, use a placeholder parameter if you also use C<return>.)
"

I guess the wording in the last parenthesized parens is insufficiently
explicit, and maybe we should change it to say that it's really a syntax
error to use placeholder blocks in statement positions.  Sounds reasonable?

Cheers,
Audrey

Reply via email to