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.
- [30 pts] Briefly define the following concepts, and give an example
illustrating each one:
- Activation record.
- Data invariant.
- Tail recursion.
- Lexical scope.
- Dangling pointer.
- Ad hoc polymorphism.
- [10 pts] Give two important advantages of information hiding, and
explain why they are important.
- [10 pts] Describe two important contributions of the IFIP working group
that defined ALGOL60, and say why they are important.
- [10 pts] Give two examples of coercions in C and explain why they could
be dangerous.
- [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] ];
- 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) ?
- Give an activation tree for the next to last (i.e., fourth)
example.
- [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).
- [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
© 2005 Joseph Goguen