Exercise Set 3

  1. What is the difference between the semantics of copying in Ada from the semantics of copying in C++?

  2. What is aliasing, and how can it occur?

  3. What is locally imperative programming, and how does it differ from globally imperative programming?

  4. In the following C++ function definition, write an @ at each point where the compiler will insert an implicit dereference. A dereference is a fetch of the contents of a box.
           int   test( int   x)
           {
             int   y,   a[  20];
             y =   x;
             a[  y] =   40;
             return   a[  y];
           }
      

  5. The effect of call-by-reference can be achieved by passing a pointer, or a box, using call-by-value. Explain how.

  6. Scheme is a typeless language. Briefly, what does that mean?

  7. Write a function to test whether a value is a member of a list in Scheme. (member x L) should return #t if x is in L and #f if x is not in L. Use function eq? to do the equality tests.

  8. What is the most general polymorphic type of function f defined by f(x) = head(left(x))? Use alpha and beta as type variables. Use notation [alpha] for the type "list of alpha" and (alpha,beta) for the type of ordered pairs whose left-hand member has type alpha and whose right-hand member has type beta.

  9. What is the most general polymorphic type of the function f defined by f(x) = head(head(x))? Use the same conventions as in the previous question.

  10. Why is polymorphism so important that most modern typed programming languages have at least some facility to support it? Specifically, where is polymorphism most important?

  11. What is the difference between name equivalence and structural equivalence of types?

  12. Is C++ strongly typed, weakly typed or untyped?