Scheme Programming Assignment

Assigned: April 17
Due: May 1

In all parts of this assignment, implement iteration using recursion. Do NOT use the iterative "do" construction in Scheme.

Part I

Write a function "(mapfun FL L)" that takes a list of functions FL and a list L and applies each element of FL to the corresponding element of L. For instance
(mapfun (list cadr car cdr) '((A B) (C D) (E F)))
should return (B C (F)) since (cadr '(A B)) => B, (car '(C D)) => C, and (cdr '(E F)) => (F).

If FL and L are of different lengths, it should stop whenever it reaches the end of either one; e.g.

(mapfun (list cadr car) '((A B) (C D) (E F))) and
(mapfun (list cadr car cdr) '((A B) (C D))) and
should both return (B C).

Part II

Write a function (filter FL X), where FL is a list of functions and X is any value, that returns the list of the elements F in FL such that (FL X) is not #f. For instance
(filter (list (lambda (Z) (equal? Z 'A))
              (lambda (Z) (member Z '(D E F)))
              (lambda (Z) (member Z '(C B A))))
should return the list consisting of the first and third lambda expression. This won't be obvious from the interpreter print out, which will just be something like (#[ (12 anon-lambda)] #[ (14 anon-l...

Note: the conditions in "if" and in "cond" are considered to be satisfied if they are not #f.
Thus (if '(A B C) 4 5) evaluates to 4.
(cond (1 4) (#t 5)) evaluates to 4.
Even (if '() 4 5) evaluates to 4, as in Scheme the empty list () is not the same as the Boolean #f. (Other versions of LISP conflate these two.)

Part III

Write a function (comparatorFuns N) which takes as argument an integer N and returns a list (f1, f2 ... fN) where fK(X) is #t if X>K. Thus
(mapfun (comparatorFuns 4) '(20 10 0 -10)) evaluates to (#t #t #f #f)
since 20>1, 10>2, 0>3, -10>4 evaluate to #t, #t, #f, #f, respectively.
(mapfun (filter (comparatorFuns 4) 3) '(10 0)) evaluates to (#t #f).