next up previous
Next: About this document

Computer Science 3675
Summer 2000
Quiz 2

You have 20 minutes. Answer all of the questions.

  1. Given the definition

    displaymath9

    show an inside-out evaluation of expression f([4,12,15,6,11]). Assume that arithmetic is done as soon as possible.

  2. Write an equational definition of a function called smallest so that smallest(n,x) is the smallest member of list n::x. For example, smallest(3, [6,4,7]) = 3 and smallest(8, [2,5]) = 2. You may presume that you have a function called min that takes the minimum of two numbers. For example, min(7,4) = 4.
  3. 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.
  4. In a purely functional language, is it ever possible to compute the same expression twice and get different values? That is, if e is an expression, and you compute e two times, could the first computation yield a different result from the second computation? Why or why not?
  5. Consider the following definition written in Astarte.

    program22

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





Karl Abrahamson
Mon Jun 19 13:39:11 EDT 2000