CMSC 10500 Fundamentals of Computer Programming 1
Autumn 2003

Homework 7

Electronic copy due: Tuesday 25 November 11:59 pm - Maclab dropbox
Hard copy due: Wednedsay 26 November noon - door of RY 161b (Sec 1 Salveter)  &  In class (Sec II  Sindhwani)

An outline of getting-started information on Dr. Scheme and an introduction to the MacLab is online at: http://www.maclab.cs.uchicago.edu/tutorials/DrScheme.html
 
1) 20.2.4  (General Contracts)

 2)  build-list is an inbuilt abstract function in scheme that consumes a natural
 number n and a function f  consuming natural numbers

(i.e     (define (build-list n f) ...)   where  f  consumes natural numbers; see section 21.2)

and outputs the  (list (f 0) ... (f (- n 1)))

 Use build list to define the function build-matrix that takes a natural number
 n and a function g (that consumes two natural numbers (>=1) and produces a
 number) and prepares the n x n matrix whose i, j th entry is (g i j).

 For example: If g is defined as - (define (g i j) (+ i j)); (build-matrix 3 g)
 should output (choose the matrix representation to be  a list of lists of numbers)

 (list
     (list 2 3 4)
     (list 3 4 5)
     (list 4 5 6))

 i.e the entry in row 1 column 2 is (g 1 2) = 3.

 3) Recall the list-pick program from section 17.3. Use list-pick to develop a
 function  lookup-matrix  that takes a matrix as defined above and two integers
 (>=1) i and j and outputs the i,j^th entry of the matrix

 For example:

 (matrix-lookup  2 3 (list
                      (list 2 3 4)
                      (list 3 4 5)
                      (list 4 5 6))
 should output 5.
 

 4) 21.2.3 (use filter to define some functions)

 5) 22.2.3  (rewrite fold using locals and first class functions)


vikass@cs.uchicago.edu

Last modified: November 19, 2003