CSE 130: PROGRAMMING LANGUAGES: PRINCIPLES AND PARADIGMS
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!
- [12 pts] Briefly answer the following, and give an example illustrating
each issue:
- What is precedence, and why is it useful?
- Why does * have higher precedence than +, and + higher than = ?
- Can ambiguities arise with operations of equal precedence?
- [12 pts] Briefly answer the following, and give an example illustrating
each issue:
- How does scope relate names and declarations?
- How does activation relate declarations and locations?
- How does state relate locations and values?
- [12 pts] Briefly answer the following, with an illustrative example in C:
- What parameter passing method is used in C?
- What is the & operator in C, and how does it relate to
call-by-reference?
- What is dereferencing?
- [9 pts] What is a functional language? Name two important functional
languages. Who were their chief designers?
- [24 pts] Given relations parent and female, and given
negation as failure not:
- Define relations mother, father, sister, and
uncle in PROLOG.
- 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.
- Show the search tree for one relation that fails.
- [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];
- What then are the values of evens t , odds
t and (evens o odds) t ?
- Justify your answer for the first expression.
- What is the type of odds?
- [6 pts] Explain the most important differences between procedures,
modules, and classes.