Computer Science 3675
Summer 2004
Practice questions for quiz 3

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

    1. zebra
    2. donkey
    3. (zebra donkey)
    4. (donkey)

  2. Write a Scheme function called descending so that (descending L) is true for a list of numbers L if L is in descending order. (The Scheme function < does a less-than test, and > does a greater-than test.) List (a b c d) is in descending order if a > b > c > d. The empty list is in descending order by definition, as is a singleton list.

  3. If you perform a single beta reduction on expression (lambda x. lambda y.x x y)(lambda z.zz), what do you get?

    1. lambda y.lambda z.zz(lambda z.zz) y
    2. (lambda x.lambda y.xxy)(lambda x lambda y.xxy)
    3. lambda x.lambda y.(xxy)(xxy)
    4. lambda y.(lambda z.zz)(lambda z.zz) y

  4. What is the purpose of the static link in a frame in the run-time stack?

  5. What is the purpose of the dynamic link in a frame in the run-time stack?

  6. What information is stored in a function closure?

  7. In C, you are not allowed to write a function inside another function. But C does allow you to treat a function as a value. Does C need to use function closures?

  8. Explain the purpose of a dereference operation in the semantics of an imperative language. (We used the name ! for the dereference operator.)

  9. If, in a C++ program, you write

      int x;
    
    then what kind of thing is the lvalue of x? What kind of thing is the rvalue of x?

  10. Are backtracking and exception handling the same thing? For example, can you use the exception handling mechanism of Java to do backtracking?

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

  12. 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.