Suggested Homework #7 (for Quiz #7 on 03/04/08)

Problem 1. Write a decorator khistory that takes a parameter k, and decorates a function by printing out for each call to the function the k last parameters sent to the function. You can assume the decorated function only takes on argument. For example:
def khistory(k):
   ...

@khistory(5)
def fac(n):
    if n <= 0: return 1
    else: return n*fac(n-1)


>>> fac(3)
[3]
[2, 3]
[1, 2, 3]
[0, 1, 2, 3]
6
>>> fac(10)
[10, 0, 1, 2, 3]
[9, 10, 0, 1, 2]
[8, 9, 10, 0, 1]
[7, 8, 9, 10, 0]
[6, 7, 8, 9, 10]
[5, 6, 7, 8, 9]
[4, 5, 6, 7, 8]
[3, 4, 5, 6, 7]
[2, 3, 4, 5, 6]
[1, 2, 3, 4, 5]
[0, 1, 2, 3, 4]
3628800
>>>
Problem 2. Assume A <: B <: C . Determine which of the following interfaces are related by a subtyping relation according to structural sub-typing.

interface I1 {
   B m(A);
}

interface I2 {
   A m(B);
   C g(B);
}

interface I3 {
   C g(A);
}

interface I4 {
   C g(C);
}