On 9/7/07, Wim Vanderbauwhede <[EMAIL PROTECTED]> wrote:
> The following program works fine in pugs r17041 (which is the rev of
> /usr/bin/pugs on feather):
>
> my $r=\{say $x+1};
> my $x=2;
> $r();
>
> With r17041, this gives 3;
> However, on the latest pugs (r17615 or later), it gives an error:
> ***
>     Unexpected "$r"
>     expecting "=", "::", context, ":" or "("
>     Variable "$x" requires predeclaration or explicit package name
>     at pugs_var_bug.p6 line 1, column 4
> It would think that the r17041 result is correct.

You can't use variables before declaring them, think use strict.  Even
if strict weren't in effect this code should not work since the $x in
the closure is not the one created after the closure:

perl -le 'my$r=sub{print $x+1};my $x = 2;$r->()'

That Perl 5 code prints 1 because undef plus one is one.

> -------
> There is also a scoping issue in r17615:
>
> my $v=1;
> if ($v) {
>         map ->$v {$v},(2);
> } else {
>         $v;
> }
>
> With r17041, this gives 2; With r17615 it gives an error:
> ***
>     Unexpected end of input
>     expecting "::"
>     Variable "$v" requires predeclaration or explicit package name
>     at pugs_scoping_bug.p6 line 6, column 15
>
> Now, if I change $v to $x in the pointy sub, it works fine.

This definitely seems like a bug.  It looks like $v is being destroyed
after it is used in the map.  It is my understanding that the $v in
the map should be treated like a temp variable (its old value should
return after the map).

Reply via email to