> =item 2
> 
> In the "liberal" approach, perl can do what amounts to "inferring
> declarations." 

This is the way it has to work if I'm going to agree with it. However, I
don't think the implementation needs to be nearly as complicated as this
RFC proposes. Consider this code:

   $x = 15;
   $y = $x;
   while ($y) {
     $z = $y;
     $x += $z;
   }

As you state, "$z is a lexical available only in the while loop".
However, you also state that Perl will automatically scope outwards to
the outermost one it find, so if I add a

   print "z = $z\n";

At the bottom, now $z is available outside as well.

Ok, but then why bother going to the trouble of scoping it so tightly to
begin with? If you're just going to automatically scope it to the
outermost one, then this is equivalent to no scoping at all (do you
see?). The only reason you'd want to scope something tightly is to:

   1. Make it inaccessible to other routines

   2. Hide another lexical variable

However, automatic scoping can't address either of these concerns. You
have to do this explicitly with my(). As such, there's no benefit to
liberal lexical scoping over package-wide scoping by default. As soon as
you access a variable outside a block, that variable is rescoped
outwards automatically.

I propose the following modifications to this RFC. You'll wind up with a
much more stable and faster implementation, I think:

   1. All variables are lexically scoped at the package
      level by default, like our().

   2. You can explicitly scope variables to a block with my().

   3. We introduce a new keyword, say "your()", that makes
      variables true dynamic variables.

The #3 one might not be necessary if we eliminate dynamics altogether
and make now() (or local or whatever) work on the lexicals correctly.

Note that the net effect is the same. Lexicals are still the default.
But the needless auto-scoping is eliminated.

-Nate

Reply via email to