CSE 130: PROGRAMMING LANGUAGES: PRINCIPLES AND PARADIGMS
Final Exam, 18 March 2005

You may try to write your answers on this sheet, but blue books are far preferable; be sure to write your name on everything you hand in! Please write brief clear answers.
1. [30 pts] Briefly define the following concepts, and give an example illustrating each one:
1. Activation record.
2. Data invariant.
3. Tail recursion.
4. Lexical scope.
5. Dangling pointer.

2. [10 pts] Give two important advantages of information hiding, and explain why they are important.

3. [10 pts] Describe two important contributions of the IFIP working group that defined ALGOL60, and say why they are important.

4. [10 pts] Give two examples of coercions in C and explain why they could be dangerous.

5. [15 pts] Given the following ML code: fun map f [] = [] | map f (x::xs) = (f x) :: (map f xs); val m = [ [11, 12, 13], [21, 22, 23], [31, 32, 33] ];
1. What are the values of   hd m ,   map tl m ,   map hd m ,   (map hd) (map tl m) , and   (map hd) (map (tl o tl) m) ?
2. Give an activation tree for the next to last (i.e., fourth) example.

6. [15 pts] Given the following PROLOG code, bird(robin). bird(eagle). bird(penguin). fly(penguin) :- !, fail. fly(B) :- bird(B). say what happens for each of the following queries, and explain why: ?- fly(eagle). ?- fly(penguin). ?- fly(sparrow).
7. [10 pts] State some simple facts for the relations parent (binary, with child the second argument) and male (unary), such as parent(joseph, alice). male(joseph). and then write PROLOG code for the binary relations brother and uncle, give a non-trivial query for each, and say what the result of each query should be.

To CSE 130 homepage
Maintained by Joseph Goguen