Computer Science 3675
Fall 2000
Practice questions for quiz 3

  1. What is the value of Scheme expression (car (cdr (cons 'horse (cons 'zebra ()))))?

  2. Write a Scheme function called drop so that (drop n L) returns the result of removing the first n members from list L. If L has fewer than n members, then (drop n L) should return the empty list. For example, (drop 2 '(4 8 3 5 7)) = (3 5 7) and (drop 3 '(5 2)) = (). Be careful to use Scheme syntax correctly.

  3. Unification is a form of pattern matching. Which of the following is not a characteristic of unification?
    1. Unification never changes the binding of a bound variable.
    2. Unification is symmetric; unifying A with B has exactly the same effect as unifying B with A.
    3. Unification is very slow, and is only used rarely during computations of logic programs.
    4. Unification can bind unbound variables.

  4. In the following C function definition, write an @ at each point where the compiler will insert an implicit fetch. (That is, make all @ operations explicit. Each variable stands for the variable, not the value of the variable.)
           int   test( int   x)
           {
             int   y,   a[  20];
             y =   x;
             a[  y] =   40;
             return   a[  y];
           }
       

  5. Explain the difference between an lvalue and an rvalue. Does every expression have an lvalue?

  6. What is one important motivation for including exception handling in a programming language?

  7. Using backtracking, write an Astarte program fragment that will print all solutions (x,y) to equation xy - 2x2 + y = 10, where x and y are both integers in the range 0,...,100. Do not use a loop or recursion. Your program fragment can fail when it is done.