in reply to Re: Re: Re: Why does Perl use dynamic scoping?
in thread Why does Perl use dynamic scoping?
However in a language with side effects, dynamic scope has the effect of treating all variables as globals.
First off, I dont grok "a language with side effects". I understand a "function with side effects" or "a function with no side effects" but I dont quite see how that can be applied to a language. And when I do, it seems logical to me to posit that "a language without side effects" doesn't do anything. Can you explain this idea to me?
Why should dynamic scoping mandate only global variables? Presumably Perl is a language with side effects so how does that square with the observation that we have dynamic scoping of elements of lexical composite variables like hashes and arrays? Or is that still fluid scoping?
use Data::Dumper; $|++; my %hash=(foo=>'bar',); sub bar(){ print "(".((caller(1))[3]||'main').")\n"; print Data::Dumper->Dump([\%hash],['*hash']); } sub foo($) { local $hash{foo}="baz"; bar(); } foo bar, bar; __END__ (main) %hash = ( 'foo' => 'bar' ); (main::foo) %hash = ( 'foo' => 'baz' ); (main) %hash = ( 'foo' => 'bar' );
:-)
Incidentally my understanding is that dynamic scoping was introduced to perl to aleviate the problems of only having globals. Not that some variables had to be global so that they could be dynamically scoped.
--- demerphq
my friends call me, usually because I'm late....
|
|---|