Spring 2002, CSE 428: Quiz 8.3 - 4 April 2002


Please write your Name, Student ID, and Section at the top of the page. By default, this quiz will be return in section 1 (afternoon section). If you want to get it back in the morning section, please write "return in section 2" at the top.
  1. [Points 2] Which of the following best describes a trait specific to functional programming languages? Pick only one answer.
    1. They make extensive use of state and side-effects.
    2. They have garbage collectors.
    3. They have strong typing.
    4. They are organized around the mathematical notion of function and function application.
  2. [Points 3] The following code describes a function in SML.
    fun g nil = 0
      | g ((x,y)::k) = x * y + (g k);
    
    What function is computed by g?
    1. The function that takes a list of pairs of numbers and returns the sum of the product of the pairs.
    2. The function takes a list and always returns 0.
    3. It does not define a function since it causes a type error.
    4. It does not define a function since it causes a match exception error.
  3. [Points 3] What is the value computed for the following expression? 19
    let val x = 15
     in let val x = 2
         in x * x
        end
        + x 
    end;
    
  4. [Points 2] What happens when SML is given the following code?
    fun f 0 = 0
      | f n = f(n - 1) - 1;
    
    1. Gives a type error.
    2. Defines a function which when applied to an integer, returns the squares that integer.
    3. Defines a function which when applied to a non-negative integer n, returns the negative of n.
    4. Defines a function that loops forever when applied to 1.

    There was a typo in this last question: the word "negative" was not in the third choice, even though this was the only correct answer. Every one will get an automatic 2 points for this question independently of their answer.