I am having a hard time understanding the output of this program with shadow and deep binding. Can someone explain it more in detail? I posted the answers below x : integer – – global procedure set x(n : integer) x := n procedure print x() write integer(x) procedure foo(S, P : function; n : integer) x : integer := 5 if n in {1, 3} set x(n) else S(n) 174 Chapter 3 Names, Scopes, and Bindings if n in {1, 2} print x() else P set x(0); foo(set x, print x, 1); print x() set x(0); foo(set x, print x, 2); print x() set x(0); foo(set x, print x, 3); print x() set x(0); foo(set x, print x, 4); print x() Here are the answers to the questions. The program prints = 10 20 30 40 with shallow binding The program prints = 10 52 00 44 with deep binding,
I am having a hard time understanding the output of this
Can someone explain it more in detail? I posted the answers below
x : integer – – global
procedure set x(n : integer)
x := n
procedure print x()
write integer(x)
procedure foo(S, P : function; n : integer)
x : integer := 5
if n in {1, 3}
set x(n)
else
S(n)
174 Chapter 3 Names, Scopes, and Bindings
if n in {1, 2}
print x()
else
P
set x(0); foo(set x, print x, 1); print x()
set x(0); foo(set x, print x, 2); print x()
set x(0); foo(set x, print x, 3); print x()
set x(0); foo(set x, print x, 4); print x()
Here are the answers to the questions.
The program prints = 10 20 30 40 with shallow binding
The program prints = 10 52 00 44 with deep binding,
Step by step
Solved in 2 steps