Programming Languages and Systems
Comprehensive Exam
August 17, 1998
Computer Science Department
University of New Mexico
The test monitor will answer some parts of these questions for you if you are unsure of what some of these terms mean. The only penalty is that you will not get any points for the part that was answered for you. You can still answer the other parts of the question. This way can get you started on a question even if you are not sure of the definitions.
You can do any questions you want. You do not have to do all the parts of a single question. Instead you can pick the parts you want to answer. Be sure that it is absolutely clear which questions you are answering.
Do enough questions (or parts of questions) to total at least 100 points. It is okay to go over 100 points and you can answer as many questions as you wish but all the questions you answer will be counted in your grade and the total will be normalized to 100 points. We will not take the best 100 points.
- Lazy languages
- (5 points) Explain what is meant by a lazy language.
- (7 points) Give a program in a lazy language that shows the lazy features of that language. (The language you use could just be Scheme with the assumption that it is a lazy version of Scheme.)
- (8 points) Give an example of a problem that is more easily programmed in a lazy language than in other types of languages. This example should be different from the program in part (b).
- (6 points) "Prolog programs are a fairly close approximation of declarative specifications." Describe what this statement means in more detail.
- (9 points) Because of (a), the Prolog interpreter may be viewed as a theorem prover. Specify in what sense this is true and in what sense this is not true. (That is, how does the procedural semantics of the prolog interpreter compare to that of a traditional theorem prover).
- (5 points) What problems does multiple inheritance create? What problems does multiple inheritance solve?
- (5 points) Suppose we only allow multiple inheritance of pure virtual functions (say in C++). Which of the problems of multiple inheritance does this solve and which does it not solve?
- (5 points) It has been said that all instance of multiple inheritance can be handled just as well as a has-a relation. Analyze this statement. In what ways it is true and in what ways it is false?
- (4 points) What is the difference between a macro and a function?
- (2 points) Briefly describe the macro facility in C++.
- (4 points) Briefly describe the macro facility in Scheme or Common Lisp.
- (4 points) Explain how the C++ template facility is a kind of macro facility. Explain why the C macro facility cannot be used to implement templates.
- (4 points) Compare a macro invocation with a function call in a lazy language. How are they different and how are they the same?
(define curry
(lamba (f)
(lambda (arg1)
(lambda (arg2)
(f arg1 arg2)))))
(define plus1 ((curry +) 1))
(plus1 5)
You can get most of the effect of
curry in C++ using objects. Show how this can be done. Do not use function pointers but you can use pointers to objects. You can overload the function call operator (operator ()) or you can just define a member function named call.
