Spring 2002, CSE 428: Quiz 8.4 - 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 have strong typing.
    2. They treat functions as first-class values.
    3. They have garbage collectors.
    4. They make extensive use of objects and methods.
  2. [Points 3] The following code describes a function in SML.
    fun g nil = 1
      | g ((x,y)::k) = (x + y) * (g k);
    
    What function is computed by g?
    1. The function takes a list and always returns 0.
    2. The function that takes a list of pairs of numbers and returns the product of the sum of the pairs.
    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 2] What is the value computed for the following expression? 14
    let val z = 5
     in let val z = 3
         in z * z 
        end
        + z
    end;
    
  4. [Points 3] What happens when SML is given the following code?
    fun f 0 = 0
      | f n = n * f(n - 1);
    
    1. Gives a type error.
    2. Defines a function which when applied to a non-negative integer n, returns the value 0.
    3. Defines a function that gives a runtime error when applied to 1.
    4. Defines the factorial function.