CSE 230: PROGRAMMING LANGUAGES: PRINCIPLES AND PARADIGMS

Final Exam, 22 March 2002


Write your name on every sheet you hand in. You will not be penalized for minor syntactic errors.
  1. [12 pts] Briefly answer the following:
    1. What is garbage collection and why is it needed in some languages?
    2. Give precise definitions for l-value and r-value.
    3. What are the differences between strong, weak, and static type checking?
    4. What is a closure?

  2. [16 pts]
    1. Define dynamic and static scoping. Give a simple program in which a procedure returns different values under dynamic and static scoping.
    2. 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.

  3. [28 pts] This question concerns the following ML function: fun lmap(f, nil) = nil | lmap(f, x::xs) = f(x) @ lmap(f, xs);
    1. What is the type of this function? Why?
    2. Write ML code to "curry" this function, and briefly explain what currying is.
    3. 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.
    4. 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.
    5. 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.
    6. What is the composition of evens with odds? Why? What is the composition of evens with itself? Why?
    7. Relate currying and composition to the lambda calculus.

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

  5. [9 pts] Define three different kinds of polymorphism and give an example of each.
     
  6. [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.
     
  7. [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