Programming Language Concepts, cs2104

advertisement
Survey of Programming Language Concepts, COSC-3308-01
Tutorial 10
Exercise 1. (A table design) A table with two seats is made of two dishes, each having
either a small plate or a big plate, either a fork or a chopstick, either a tea pot or a cup,
and a porcelain spoon or a metal spoon. The constraint is that the seat with the chopstick
has a tea pot and the one with the fork has a cup. The goal is to help the table designer
pick the proper dishes for a table.
Exercise 2. (Assigning digits to letters) Assign distinct digits to the letters A, B, and C
such that ABC = AB + BC + CA represents a valid addition, where ABC is a number in
decimal bases.
Exercise 3. (MCQ1) What is the environment E, and the single-assignment store σ after
executing the line 5 (but before line 6) of the following Oz program (the lines are
numbered for our reference, in a real Oz program these numbers do not appear):
1. Y = 1
2. local X in
3.
X = 2 + Y
4.
local X in
5.
X = 3 + Y
6.
end
7. end
a)
b)
c)
d)
e)
E={Y y, X x}, σ={y=1, x=3}
E={Y y, X x}, σ={y=2, x=4}
E={Y y, X x}, σ={y=0, x=4}
E={Y y, X x}, σ={y=0, x=2}
none of the above.
Exercise 4. (MCQ2) What will be displayed in the browser window after executing the
following Oz program (the lines are numbered for our reference, in a real Oz program
these numbers do not appear):
1. declare
2. fun lazy {F X} 2*X end
3. fun lazy {G X} 3*X end
4. fun {H X} 4*X end
5. A = {F 3}
6. {Browse A}
7. B = {G 4}
8. {Browse B}
9. C = A + {H 5}
10. {Browse C}
a) 6 12 26
b) 6 B 26
c) A B 26
d) errors at lines 5 and 7, because calls of F and G do not
contain the keyword “lazy”
e) None of the above.
Exercise 5. (Written answer 1) Given the Oz functions F1 and F2, construct the
equivalent Oz program written in the Kernel language for the expression
{F1 A {F2 B C} D}
Please comment over the correctness of the translation.
Hints:
This theoretical exercise is a particular instance of translation from high-level Oz to the
Oz kernel language.
Identify the proper similar slides, and adapt the translation to it.
Download