COM1340 - Winter 2003
Assignment 4
Due: March 7, 2003

Set DrScheme to use the PLT | Graphical language level.

For each exercise, provide a procedure definition and at least four tests (different from the provided examples) that use eq? or equal?, as appropriate, to compare expected results with the actual results of applying your procedure.

Print out your work. On your printout, legibly write your name and ``COM1340 -- Assignment 4.''

1.) Write a Scheme function make-mapper that takes a unary function f and returns a function which, when applied to a list lst, returns the same value as (map f lst). In other words

 ((make-mapper f) lst) = (map f lst)

For example:

 ((make-mapper -) '(3 4 5)) => (-3 -4 -5)
 ((make-mapper odd?) '(3 4 5)) => (#t #f #t)
 ((make-mapper (compose - -)) '(3 6 9)) => (3 6 9)
 ((make-mapper symbol?) '(3 4 foo)) => (#f #f #t)

where - is unary negation and compose is function composition. You need to put

  (require (lib "etc.ss"))

in your code to make compose available.

2.) Write a Scheme function zip that takes two Scheme lists of equal length and produces a list of two-element lists, where the two elements are corresponding elements in the input lists. Your implementation must use Scheme map.

 (zip '(a b c) '(d e f)) => ((a d) (b e) (c f))
 (zip '(1 2 3) '(d e f)) => ((1 d) (2 e) (3 f))
 (zip null null) => ()

Last modified: Tues, Feb 25, 2003, 3:27 pm US/Eastern
HTML conversion by TeX2page 4p14a