Consider the following pseudocode program Suppose dynamic sc
Consider the following pseudo-code program: Suppose dynamic scoping with shallow binding is used by the interpreter to execute this code. What is the value printed by the program? Suppose dynamic scoping with deep binding is used by the interpreter to execute this code. What is the value printed? Suppose static scoping is used. What is the value printed by the program?
Solution
1) Now here Dynamic Scoping with shallow binding which binds the environment at the time the procedure is actually called
So here when procedure p is called P(1,add) inside it sum takes the value passed as x hence 1 , shallow binding looks for the nearest variable which corresponds the name hence here the value of sum would be 1.
2) Now dynamic scoping with deep binding is when the it binds the environment the time procedure is passed as agrument.
add being passed as agrument sum = 0 , amount =1 and sum is global variable it write to it, the value of sum becomes 1
