Dave (>), Carl (>>):
>  my $foo;
>  # ...later in the same scope...
>  my $foo; # illegal Perl5, legal Perl6

No, that's perfectly legal in perl5; it just generates a warning:

    use warnings;
    my $x = 1;
    my $f1 = sub { $x };
    my $x = 2;
    my $f2 = sub { $x };
    printf "f1=%d f2=%d x=%d\n", $f1->(), $f2->(), $x;

which gives

    $ perl588 /tmp/p
    "my" variable $x masks earlier declaration in same scope at /tmp/p line 6.
    f1=1 f2=2 x=2

Ah, your quite right. Going back, I see that this was indeed pointed
out in the original thread as well; I just didn't catch it then.

http://groups.google.com/group/perl.perl6.language/browse_frm/thread/05c902b290fb7a5a/f9506f5acde3ceb4?#f9506f5acde3ceb4

FWIW, I think a warning is fine. (Because in my world a warning means
that something isn't "perfectly legal".) Maybe it's in line with
Perl's policy of being forgiving when possible to give a warning
instead of a compile-time error. That's fine.

What bothers me is that one might not even get a warning in Perl 6.
Since a duplicated variable declaration is often due to programmer
confusion, it seems like we're passing up such a fine opportunity for
telling them about it. What underlying design decision is it that
prevents us from giving a warning here, as in Perl 5?

Pugs currently executes the above code and gives the same output, but
no warning:

  $ pugs test.pl
  f1=2 f2=2 x=2

// Carl

Reply via email to