On Thu, Apr 03, 2008 at 12:43:58AM +0800, Audrey Tang wrote:
> Larry Wall 提到:
>> Yes, unless we decide we need something like that for list
>> comprehensions. Maybe looping modifiers allow placeholders in what
>> would otherwise be an error...
>
> Sure. How about this:
>
> "
> Use of a placeholder parameter in statement-level blocks triggers a
> syntax error, because the parameter is not out front where it can be
> seen. However, it's not an error when prefixed by a C<do>, or when
> followed by a statement modifier:
>
> # Syntax error: statement-level placeholder block
> { say $^x };
>
> # Not an syntax error, though $x doesn't get the argument it wants
> do { say $^x };
>
> # Not an error at all
> { say $^x } for 1..10;
> "
I was originally thinking just loop modifiers, but I suppose
{ say $^x } if foo();
also can be made to make some kind of sense, in the same way that
if foo() -> $x { say $x }
is supposed to work. And we have to do it like that anyway if
we want to say something like:
{ say $^x } if .odd for 1..10;
> I do find it interesting that, because "any block just inside a left
> parenthesis is immediately called like a bare block", we have:
>
> my $x = {1+1}; # $x is a Code
> my $y = ({1+1}); # $y is 2!
>
> Is that correct?
Yes, current STD has the inside of () and [] as <statementlist>,
which throws away all but the last statement. Arguably [] at least
should probably be <semilist> though, and maybe () too.
my @x := [{1+1}; {2+2}]; @x is currently [4], should be [2,4]?
my @x = ({1+1}; {2+2}); same deal?
Larry