Final Exam, 22 March 2002

Write your name on every sheet you hand in. You will not be penalized for minor syntactic errors.

- [12 pts] Briefly answer the following:
- What is garbage collection and why is it needed in some languages?
- Give precise definitions for l-value and r-value.
- What are the differences between strong, weak, and static type checking?
- What is a closure?

- [16 pts]
- Define dynamic and static scoping. Give a simple program in which a procedure returns different values under dynamic and static scoping.
- Define call by name and call by reference. Give a program in which a procedure returns different values under call by name and call by reference.

- [28 pts] This question concerns the following ML function:
fun lmap(f, nil) = nil | lmap(f, x::xs) = f(x) @ lmap(f, xs); - What is the type of this function? Why?
- Write ML code to "curry" this function, and briefly explain what currying is.
- Apply your curried version of
`lmap`

to a suitable`f`

to get a function that adds one to each element of a list of integers; now do the same for subtracting one. - Write ML code that applies
`lmap`

to a suitable`f`

to get a function`evens`

that deletes all odd numbers from a list of integers. - Now use the functions that you have defined above to write an ML
function
`odds`

that deletes all even numbers from a list of integers. - What is the composition of
`evens`

with`odds`

? Why? What is the composition of`evens`

with itself? Why? - Relate currying and composition to the lambda calculus.

- [6 pts]
- Which language first introduced exception handling?
- Who were the chief designers of Ada and C++?
- Who introduced the notions of l-value and r-value?

- [9 pts] Define three different kinds of polymorphism and give an example
of each.

- [16 pts] Say intuitively what the following Prolog code does:
m(X, [], X). m([], X, X). m([X|Xs], [Y|Ys], [X|Zs]) :- X < Y, m(Xs, [Y|Ys], Zs). m([X|Xs], [Y|Ys], [Y|Zs]) :- Y < X, m([X|Xs], Ys, Zs). m([X|Xs], [X|Ys], [X|Zs]) :- m([X|Xs], Ys, Zs). Draw the search graph for the query`m([1,2], [2,3], A)`

and briefly explain what it means.

- [13 pts] Write OBJ code that computes the same function as
`m`

in problem 6 (regarding the third argument as a function of the other two), and sketch how you could prove that this code is correct.**Hint:**Consider structural induction.

To CSE 230 homepage

Maintained by Joseph Goguen

© 2002 Joseph Goguen