Draw the the environment diagram that results from executing the code below until the entire program is finished or an error occurs.
def person(name, age):
def brain(ask):
if ask == 'name':
return name
elif ask == 'age':
return age
return brain
def name(guy):
return guy('name')
def age(gal):
return gal('age')
my_name, my_age = 'Marv', 21
marv = person(my_name, my_age)
dan = person('Dan', age(marv) + 7)
Draw the the environment diagram that results from executing the code below until the entire program is finished or an error occurs.
def peace(today):
harmony = love + 2
return harmony + today(love + 1)
def joy(peace):
peace, love = peace + 2, peace + 1
return love // harmony
love, harmony = 3, 2
peace(joy)
Draw the the environment diagram that results from executing the code below until the entire program is finished or an error occurs.
def k(g, b):
def n(s, a):
return g - p
return b(n(b, p))
g, p = 3, 7
k(p + 1, lambda s: g + 3)
Draw the the environment diagram that results from executing the code below until the entire program is finished or an error occurs.
y = 3
def out(h, m):
y = 5 * m
def inner():
return y
if m == 0:
return h
else:
return out(inner, m - 1)
v = out(None, 1)()
Draw the environment diagram that results from executing the code after the entire program is finished. No errors occur during the execution of this example.
def scramble(egg):
return [egg, over(egg)]
def over(easy):
easy[1] = [[easy], 2]
return list(easy[1])
egg = scramble([12, 24])
For each of the following code fragments, draw the final state of the program in boxes and arrows.
Code:
L = Link(1, Link(2))
P = L
Q = Link(L, Link(P))
P.rest.rest = Q
Code:
L = Link.empty
for i in range(3):
L = Link(i, L)
Code:
P = Link(0, Link(1, Link(2)))
def crack1(L):
if L is Link.empty:
return (Link.empty, Link.empty)
L1, L2 = crack1(L.rest)
return (Link(L.first, L2), L1)
Q, R = crack1(P)
Code:
P = Link(0, Link(1, Link(2)))
def crack2(L):
if L is Link.empty:
return (Link.empty, Link.empty)
L1, L2 = crack2(L.rest)
L.rest = L2
return (L, L1)
Q, R = crack2(P)