Computer Science 3675
Fall 2017
Practice Questions for Quiz 2

  1. Which of the following are true, and which are false?

    1. All compilers translate to machine language.

      Answer

    2. All programming language implementations are compilers.

      Answer

    3. Compiled code typically runs one or two orders of magnitude faster than interpreted code.

      Answer

    4. Interpreters are less portable than compilers.

      Answer

    5. A garbage collector based on reference counts cannot collect cyclic structures.

      Answer

  2. What is a just-in-time compiler?

    Answer

  3. Explain what fragmentation is, and how a garbage collector can eliminate it.

    Answer

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

    Answer

  5. What is the purpose of the dynamic link in a frame in the run-time stack?

    Answer

  6. What information is stored in a function closure?

    Answer

  7. In C, you are not allowed to write a function inside another function. But C does allow you to treat a function as a value. Does C need to use function closures?

    Answer

  8. Suppose that function f is defined by

    f(x, y) = (y, head(x))
    What is the most general polymorphic type of f? Use type variables of the form <a> and <b>.

    Answer

  9. Suppose that function f is defined by

    f(x, y, z) = x :: y :: z
    What is the most general polymorphic type of f?

    Answer

  10. Function select is intended to find a value in a list that has a given property. select(p, x, d) should yield the first member z of list x so that p(z) is true, if there is one. (Notice that p is a function that yields a boolean result.) If there is no member z of list x so that p(z) is true, then select(p, x, d) should yield d.

    For example, suppose that isOdd(n) returns true if n is an odd integer. Then select(isOdd, [2,4,5,7,4], 0) = 5, since 5 is the first odd member of list [2,4,5,7,4]. select(isOdd, [2,4,6,8], 0) = 0, since list [2,4,6,8] has no odd member.

    1. What is the type of function isOdd? Answer

    2. What is the most general polymorphic type of function select? Answer

    3. Write an equational definition of select. Answer