3.18 Consider the following pseudocode: x : integer procedure set_x(n: integer) x := n ➖➖➖➖ procedure print_x() global write integer (x) else procedure foo (S, P: function; n : integer) x: integer := 5 if n in (1, 3) set_x (n) else S(n) if n in {1, 2} print_x() 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() Assume that the language uses dynamic scoping. What does the program print if the language uses shallow binding? What does it print with deep binding? Why?

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 8SA
icon
Related questions
Question
Please help me with this Principles of programming language homework question
3.18 Consider the following pseudocode:
x: integer
procedure set_x(n: integer)
x := n
procedure print_x()
write integer (x)
global
procedure foo (S, P: function; n : integer)
x : integer := 5
if n in (1, 3)
set_x (n)
else
S (n)
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()
Assume that the language uses dynamic scoping. What does the program print if the language
uses shallow binding? What does it print with deep binding? Why?
Transcribed Image Text:3.18 Consider the following pseudocode: x: integer procedure set_x(n: integer) x := n procedure print_x() write integer (x) global procedure foo (S, P: function; n : integer) x : integer := 5 if n in (1, 3) set_x (n) else S (n) 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() Assume that the language uses dynamic scoping. What does the program print if the language uses shallow binding? What does it print with deep binding? Why?
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Returning value from Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning