

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Practice questions and answers for quiz 3a in the cis 352 course. The questions cover various topics such as thunks, variable aliasing, let and letrec, expressed values and denoted values, abstract syntax and concrete syntax, and the purpose of environment and continuation in the continuation-passing interpreter. The document also includes exercises to fill in the table with the values printed under each of the listed parameter passing schemes.
Typology: Quizzes
1 / 3
This page cannot be seen from the preview
Don't miss anything!
Question 1. Answer 3 out of the following 6 questions.
(a) Briefly explain what a thunk is and how thunks are used in implementing programming languages.
(b) Give a brief definition and an example of variable aliasing.
(c) Briefly explain the difference between how let and letrec are implemented. Hint: What goes wrong if we try to evaluate the following? let fact = proc(n) if zero?(n) then 1 else *(n,(fact (sub1(n)))) in (fact 6)
(d) Explain the difference between expressed values and denoted values and sketch a situation where they differ.
(e) Briefly explain the difference between abstract syn- tax and concrete syntax and the r ˆole abstract syn- tax in programming language implementation.
(f) In the continuation-passing interpreter, eval-expres- sion takes three arguments: an expression, an en- vironment, and a continuation. Briefly explain the purpose of the environment and the continutation.
Question 2. This question assumes that call-by-value parameter passing is used.
(a) (8 points) Consider the following code.
let x = 2 y = 4 z = 6 in let f = proc(x) +(x,y) g = proc(t,y) *(t,y) y = 8 in (f (g z 10))
(i) What is the value of this expression under lexical scoping? (ii) What is the value of this expression under dynamic scoping?
(b) (8 points) Consider the following code.
let m = 0 q = 1 r = 10 in let m = 4 p = proc(x,t) begin set r = +(m,200); *(r,t) end in let q = 5 k = proc(a,m) begin set m = 2; (p add1(m) *(a,q)) end in (k m r)
(i) What is the value of this expression under lexical scoping? (ii) What is the value of this expression under dynamic scoping?
Question 3. Consider the following code, assuming lexical scoping.
let b = 7 c = 2 d = 0 in let f = proc(k) begin set d = +(d,1); *(k,10) end g = proc(j) begin set d = +(d,100); *(j,10) end h = proc(x,y,z,w) begin set y = x; set c = +(z,1); set y = *(x,x); set b = add1(b); write(y,z) end in begin (h (f 1) b c (g 2)); write(b,c,d) end
Fill in the table below with the values printed under each of the listed parameter passing schemes.
write(y,z) from h write(b,c,d) from the main begin-end
(a) call-by-value
(b) call-by-reference
(c) call-by-name
(d) call-by-need
(e) call-by-value-result