Most Perl 6 will look like Perl 5

Nicholas Clark nick at ccl4.org
Fri Jan 25 10:21:12 GMT 2008


On Fri, Jan 25, 2008 at 09:59:19AM +0000, Jonathan Stowe wrote:
> On Thu, 2008-01-24 at 15:09 -0800, Ovid wrote:
> >  For example, this:
> > 
> >   my $is_ok = 1;
> >   for my $t (0 .. 6) {
> 
> ...
> 
> > Becomes this:
> > 
> >   my $is_ok = 1;
> >   for 0..6 -> $t {
> 
> I'll admit to have stopped paying attention to Perl 6 some years when
> most of the discussion might have just as well have been pinhead angel
> counting, but to me the above seems to me to be a completely gratuitous
> change in syntax for no apparent benefit. Now I am sure someone is going
> to reply "but but ... ", and I can assure that the wrong answer will be
> to explain it to *me* in relation to some fashionable CS idea or
> functional programming paradigm or whatever.

IIRC it's because this is irregular:

$ perl
use strict;
my $is_ok = 1;
for my $t (0 .. 6) {
  # stuff
}
print $t;
__END__
Global symbol "$t" requires explicit package name at - line 6.
Execution of - aborted due to compilation errors.


that 'my $t' is actually only valid inside the block, yet it is declared
outside the block.

The new syntax is regular, in that all declarations with 'my' are for the
block in which they are found.

IIRC there was fun when the C++ standard moved the scope of variable
declarations inside the () of for loops to achieve similar regularity.
For example, gcc 2.6 did it the old way, gcc 2.7 did it the new way. Code
broke.

Nicholas Clark


More information about the london.pm mailing list