Final Exam, 15 March 2004

You may write your answers on this sheet, but blue books are far preferable; be sure to write your name on everything you hand in!
  1. [12 pts] Briefly answer the following, and give an example illustrating each issue:
    1. What is precedence, and why is it useful?
    2. Why does * have higher precedence than +, and + higher than = ?
    3. Can ambiguities arise with operations of equal precedence?

  2. [12 pts] Briefly answer the following, and give an example illustrating each issue:
    1. How does scope relate names and declarations?
    2. How does activation relate declarations and locations?
    3. How does state relate locations and values?

  3. [12 pts] Briefly answer the following, with an illustrative example in C:
    1. What parameter passing method is used in C?
    2. What is the & operator in C, and how does it relate to call-by-reference?
    3. What is dereferencing?

  4. [9 pts] What is a functional language? Name two important functional languages. Who were their chief designers?
  5. [24 pts] Given relations parent and female, and given negation as failure not:
    1. Define relations mother, father, sister, and uncle in PROLOG.
    2. Assuming that Mary and John are parents of Bill and Sue; that Martha and Bob are parents of Mary and Rich; and that Martha, Mary, Sue are female, give one example where each of your four relations holds, and one where it does not hold.
    3. Show the search tree for one relation that fails.

  6. [25 pts] Given the following ML code: fun lmap(f, nil) = nil | lmap(f, x::xs) = f(x) @ lmap(f,xs); fun even 0 = true | even 1 = false | even n = even(n-2); fun odd n = even(n-1); fun fl f x = if f x then [x] else nil; fun evens x = lmap(fl even, x); fun odds x = lmap(fl odd, x); val t = [1,2,3,4,5,6,7];
    1. What then are the values of   evens t ,   odds t   and   (evens o odds) t ?
    2. Justify your answer for the first expression.
    3. What is the type of odds?

  7. [6 pts] Explain the most important differences between procedures, modules, and classes.