Homework 4 (Due Monday 2/14/2011 at 10:00am)

Use the Intermediate Student with lambda language level. You can choose to use lambda, as appropriate, in any of the assigned problems. [For 2011: You may not use local to define functions; all program functions (including helpers) must be defined at the top level.]

Book Problems:

Hints for writing the "split" function: 

A 2-element structure can be defined (you MUST do this somewhere!) in one of two ways:

a) Define your own structure.   The CS term for a pair of elements is "dyad", so for instance, one could define a structure as

(define-struct dyad (first second)) 

Review your notes on how "define-struct" automatically creates constructor and accessor functions.    You will still need to, in words, define what types the "first" and "second" elements are supposed to be (note: there are several ways to do this). 

b) Use Scheme's built-in functions.    First, you must explicitly define that you are going to use a list of exactly two elements, i.e. (list a b).    Scheme already provides functions to access the first and second elements of such a list, called, oddly enough, "first" and "second":

(first (list a b)) ==> a

(second (list a b)) ==> b 

Again, you will still need to define exactly what types the first and second elements are supposed to be.   DO NOT USE (first (rest lon)) as this an encapsulation violation of an indefinite-length list!

Think simple!
Follow these important rules whenever you write function on a list using structural recursion (note that the generative recursion that mergesort uses follows slightly different rules):