CSC 8310 ML Quiz
Villanova University, Spring 2001
David Matuszek
     Section 2

      Name ____________________________________________

 

  1. (8 points) Given the following function definition:
    fun mung [] = []
    |   mung (x::y::rest) = (x * y)::(mung rest); 
    what is the value returned by each of the following function calls?
        mung [1,2];
    
    
        mung [1,2,3,4];
         
  2. (8 points) Given the following function definition:
    fun mapkin L = map (fn x => x mod 2 = 0) L; 
    what is the result of the following function calls?
        mapkin [1,2,3];
    
    
        mapkin [~2, ~1, 0, 1, 2];
    
    
  3. (3 points each) Use the formal ML notation for types to describe the type of each of the following expressions. That is, if you typed the expression at the prompt, what would ML display for the type?

    1. #"a"


    2. (3, 4.5)


    3. op mod


    4. round


    5. explode


    6. ( )


  4. (3 points each) Write the name or symbol of the function that does each of the following:

    1. ________ Computes the logical "or" of two boolean values.

    2. ________ Computes the logical "not" of a boolean value.

    3. ________ Convert a string to a list of characters.

    4. ________ Inserts an element into the front of a list.

    5. ________ Returns a new list with the first N elements of the given list removed.

    6. ________ Returns the second element of a tuple.

  5. (3 points each) True or False:

    1. ________ ML is strongly typed.

    2. ________ All functions in ML take one parameter.

    3. ________ Elements of a list must all be the same type.

    4. ________ ML's boolean operators are: and, or, not.

    5. ________ Symbolic identifiers in ML cannot contain digits.

    6. ________ Anonymous functions in ML cannot be recursive.

  6. (3 points each) True or False:

    1. ________ Call-by-reference parameter transmission is done by passing pointers.

    2. ________ Mark-and-sweep garbage collection prevents dangling references.

    3. ________ Garbage collection by reference counts prevents dangling references.

    4. ________ Java uses mark-and-sweep garbage collection.

    5. ________ C++ uses reference counts to do garbage collection.

    6. ________ Pascal has less need for pointers than C does.

    7. ________ Values placed on the stack do not need to be garbage collected.

    8. ________ Variables have a lifetime, while values have a scope.

    9. ________ C++ is generally better than Java for real-time programming.

    10. ________ Java's access modifiers are based on those of Algol 60.