Computer Science 3675
Fall 2016
Practice Questions for Quiz 4

  1. Consider the following definition written in Cinnameg.

        Define f(n) = (:n*n :: f(n+1):).
    
    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.) Evaluating a promise does not change the value that is represented, it only changes the representation of the value.

    Answer

  2. Consider the following definition written in Cinnameg.

        Define f(n) = (: n :: f(n*n) :).
    
    What value does expression f(2) compute? Give the full value, as it would be if it were examined.

    Answer

  3. Write an equational definition of rfold(i, f, L) so that rfold(i, f, [a,b,c]) = f (a, f (b, f (c, i))). Generalize to an arbitrarily long list.

    To get a better understanding of this, suppose that the function (f ) is a binary operator * (whose meaning could be anything), where operator * is right-associative. That is, a*b*c means a*(b*c). Then rfold(i, *, [a,b,c]) = a*b*c*i and rfold(x, *, [a,b,c,d]) = a*b*c*d*x.

    By definition, rfold(i, f, [ ]) = i.

    Answer

  4. What is the significance of λ-calculus to the semantics of programming languages?

    Answer

  5. If you perform a single β-reduction on (λxy.yx)(wz), what do you get?

    Answer

  6. If you perform a single β-reduction on expression (λxy.xxy) (λz.zz), what do you get?

    1. λyz.zz (λz.zz) y
    2. xy.xxy) (λxy.xxy)
    3. λxy.(xxy) (xxy)
    4. λy.(λz.zz) (λz.zz) y

    Answer

  7. A combinator is a term of λ-calculus that has no free variables. Which of the following are combinators?

    1. λxy.x
    2. λxyz.xz (yz)
    3. λxy.yzx

    Answer

  8. If you perform a single β-reduction on (λx.x x)(λx.x x), what do you get?

    Answer

  9. Suppose that spread(x) takes a list x and yields another list that contains all members of x with a 1 after it. For example,

    Write a definition of spread(x) in Cinnameg that only computes as much of the result list as is needed by the program.

    Answer