Problem 3. Parameter Passing Consider the following block. Assume dynamic scoping. 1 ( int y; 2 int z; 3 4 e 5 6 7 8 e 9 10 11 12 13 14 15 }; y := 6; { int }; f(int a) { y = a +1; return (y+a) }; int g(int x) { y = f(x+1)+2; z = f(x-y+2); return (z+1) } z = g(y*2); a) Draw the runtime stack after each line executes given that both parameters a and x are passed using Call-by-Name. What are the values of y and z after line 13 executes? b) Draw the runtime stack after each line executes given that both parameters a and x are passed using Call-by-Need. What are the values of y and z after line 13 executes?

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter2: Using Data
Section: Chapter Questions
Problem 14RQ
icon
Related questions
Question
Problem 3. Parameter Passing
Consider the following block. Assume dynamic scoping.
1 = {
2
3
4 e
5
LO
01
7
8
9
10
11
12
13
14
15
};
int y;
int z;
y = 6;
{ int f(int a) {
};
y := a+1;
return (y+a)
};
int g(int x) {
y = f(x+1)+2;
z = f(x-y+2);
return (z+1)
}
Z := g(y*2);
a) Draw the runtime stack after each line executes given that both parameters a and x are passed
using Call-by-Name. What are the values of y and z after line 13 executes?
b) Draw the runtime stack after each line executes given that both parameters a and x are passed
using Call-by-Need. What are the values of y and z after line 13 executes?
Transcribed Image Text:Problem 3. Parameter Passing Consider the following block. Assume dynamic scoping. 1 = { 2 3 4 e 5 LO 01 7 8 9 10 11 12 13 14 15 }; int y; int z; y = 6; { int f(int a) { }; y := a+1; return (y+a) }; int g(int x) { y = f(x+1)+2; z = f(x-y+2); return (z+1) } Z := g(y*2); a) Draw the runtime stack after each line executes given that both parameters a and x are passed using Call-by-Name. What are the values of y and z after line 13 executes? b) Draw the runtime stack after each line executes given that both parameters a and x are passed using Call-by-Need. What are the values of y and z after line 13 executes?
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
ADT and Class
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
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT