On Mon, 03 Sep 2001 19:29:09 -0400, Ken Fox wrote:

>> *How* are they "fundamentally different"?
>
>Perl's "local" variables are dynamically scoped. This means that
>they are *globally visible* -- you never know where the actual
>variable you're using came from. If you set a "local" variable,
>all the subroutines you call see *your* definition.
>
>Perl's "my" variables are lexically scoped. This means that they
>are *not* globally visible. Lexicals can only be seen in the scope
>they are introduced and they do not get used by subroutines you
>call. This is safer and a bit easier to use because you can tell
>what code does just by reading it.
>
>> But in this case the pad is actually a full symbol table.  The
>> concept is the same, the data structure is different.
>
>The concept isn't the same. "local" variables are globals. 

This is nonsense.

Firs of all, currently, you can localize an element from a hash or an
array, even if the variable is lexically scoped. This works:

        use Data::Dumper;
        my %hash = ( foo => 42, bar => '007' );
        {
             local $hash{foo} = 123;
             print "Inner: ", Dumper \%hash;
        }
        print "Outer: ", Dumper \%hash;
-->
        Inner: $VAR1 = {
                  'foo' => 123,
                  'bar' => '007'
                };
        Outer: $VAR1 = {
                  'foo' => 42,
                  'bar' => '007'
                };

So local and global are not one and the same concept.

Unfortunately, this doesn't work with plain lexical scalars. I wonder
why. Really.

How are globals conceptually different than, say, globally scoped
lexicals? Your description of global variables might just as well apply
to file scoped lexicals. Currently, that is the largest possible scope,
but why stop there?

Typeglobs are on the verge of extinction. Perhaps the current concept of
symbol tables may well follow the same route? A symbol table will be
different in perl6, anyway. If the implementation of lexicals is
consistently faster than that of globals, perhaps globals ought to be
implemented in the same way as lexicals?

From the top of my head, I can already think of one reason against:
dynamic creating of new global variables, for example while loading new
source code. It's a situation you just can't have with lexicals. For
globals, it can, and will, happen, and it would require extending the
"global pad" or something like that.

-- 
        Bart.

Reply via email to