Computer Science 3675
Summer 2001
Practice questions for quiz 3

  1. By choosing among the operations lfold, rfold, map and select, write a definition for each of the following that does not use recursion or loops.

    1. Write a function called doubleAll that takes a list x of numbers as its parameter and produces a list of the doubles numbers in list x as its result. For example, doubleAll([5,2,19,3]) = [10,4,38,6].

    2. Write a function called firstPos that returns the first positive number from a list of numbers. For example, firstPos([-4, -2, 0, 6, 12, -9]) = 6. Presume that the list has at least one positive number in it.

  2. Consider the following definition written in Astarte.

        Define f(?n) = (:n*n :: f(n+1):).
      
    What value does expression f(2) compute? Give the full value, as it would be if it were examined. (It suffices to give a clear description of the full value.)

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

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

  5. Write a Scheme function called prefix so that (prefix x y) returns true if list x is a prefix of list y. Be careful to use Scheme syntax correctly.

  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.