-
March 1st, 2008, 04:57 PM
#1
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??
-
March 1st, 2008, 07:36 PM
#2
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
-
March 1st, 2008, 09:00 PM
#3
Re: dynamic vs static scoping...
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
-
March 1st, 2008, 11:52 PM
#4
Re: dynamic vs static scoping...
Don't get that...
F() doesn't PRINT anything
-
March 2nd, 2008, 12:04 AM
#5
Re: dynamic vs static scoping...
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?
-
March 2nd, 2008, 01:02 AM
#6
Re: dynamic vs static scoping...
I don't see 6 Print statements
-
March 2nd, 2008, 01:37 AM
#7
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
-
March 2nd, 2008, 10:07 PM
#8
Re: dynamic vs static scoping...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|