Re: Remember: Outlaw to declare a lexical twice in the same scope
Steve Lukas (): Hi @larry, I want to remember to my proposal from september 2006. It targets on changing S04. The discussion is summarized on: http://www.oreillynet.com/onlamp/blog/2006/09/weekly_perl_6_mailing_list_sum_3.html So, please change S04 as discussed. I, too, would like to point to this as an important issue. It would be nice if someone could point to a good reason to change this behavior from the one in Perl 5. I might be all wrong in my reasons to be horrified at the following: my $foo; # ...later in the same scope... my $foo; # illegal Perl5, legal Perl6 But if I am, I would like to know why. Perl6 is strict in not letting the programmer declare a variable less then once, why shouldn't it be strict in not letting them declare it more than once? -- masak
Re: Remember: Outlaw to declare a lexical twice in the same scope
On Sat, Jan 27, 2007 at 10:23:03AM +0100, Carl Mäsak wrote: 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 -- But Pity stayed his hand. It's a pity I've run out of bullets, he thought. -- Bored of the Rings
Re: Remember: Outlaw to declare a lexical twice in the same scope
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
Re: Remember: Outlaw to declare a lexical twice in the same scope
Carl Mäsak writes: my $foo; # ...later in the same scope... my $foo; # illegal Perl5, legal Perl6 That isn't illegal in Perl 5. It yields the warning: my variable $foo masks earlier declaration in same scope but it does work. Smylers
Remember: Outlaw to declare a lexical twice in the same scope
Hi @larry, I want to remember to my proposal from september 2006. It targets on changing S04. The discussion is summarized on: http://www.oreillynet.com/onlamp/blog/2006/09/weekly_perl_6_mailing_list_sum_3.html So, please change S04 as discussed. Thanks Stefan - Expecting? Get great news right away with email Auto-Check. Try the Yahoo! Mail Beta.