dynamic vs static scoping...
hey everyone.. i am trying to understand the difference between dinamic and static scoping...
can someone please explain me this short problem and what would be the results..
Code:
int a = 27;
f() {
int a = 32;
g();
}
g() {
print a;
{
int a = 99;
h();
}
}
h() { print a; }
print a;
f();
g();
h();
what i mean is what would be the output of the above program using static scope and the output using dynamic scop, assuming that each invocation of print a prints the value of a on a separate line.
also.. is it true that dynamic scope is used in most popular programming languages??
Re: dynamic vs static scoping...
static scope would output
27
27
27
27
27
27
dynamic scope would output
27
32
99
27
99
27
basically all languages that are still used today use static scope, because dynamic scope is very difficult to reason about
some ideas of dynamic scope are used in object-oriented programming with dynamic binding of virtual methods
Re: dynamic vs static scoping...
Quote:
Originally Posted by spoon!
static scope would output
27
27
27
27
27
27
dynamic scope would output
27
32
99
27
99
27
basically all languages that are still used today use static scope, because dynamic scope is very difficult to reason about
some ideas of dynamic scope are used in object-oriented programming with dynamic binding of virtual methods
thank you soooo much
Re: dynamic vs static scoping...
Don't get that...
F() doesn't PRINT anything
Re: dynamic vs static scoping...
Quote:
Originally Posted by dglienna
Don't get that...
F() doesn't PRINT anything
it calls g function... did you find a mistake in other guy's answer?
Re: dynamic vs static scoping...
I don't see 6 Print statements
Re: dynamic vs static scoping...
1. there is a print before f is called
2. g prints
3. h prints
4. g prints
5. h prints
6. h prints
Re: dynamic vs static scoping...