MP2
CS603 Organization of Programming Languages
Due 12 March 2003

University of Alabama
Department of Computer Science
Spring 2003

Purpose

The purpose of this assignment is to do some Scheme programming.

Problem Description

Do Exercises 2 and 5.a, 5.b, 5.e, 5.f, 5.g, 5.h and 5.k from Chapter 3 of the textbook. Rather than taking the verbatim text from the exercises in the textbook, I have included transcripts from my implementation of the assignments and includes some hints along the way. Your solutions should produce the same results, with nothing extra. Please note and follow precisely the instructions for handing in your programs. A listing of the contents of the initial basis is found on page 100. You might want to try the functions from exercise 5 before tackling exercise 2.

Hint--For exercise 2, first try writing an expression that returns a list of booleans if the elements of a list are divisible by some number. Then, write an expression that returns a list of booleans if the elements of the list are not divisible by some number. Then, choose one of the higher-order-functions that takes such an expression and computes the appropriate final answer.

-> (remove-multiples-too 2 '(1 2 3 4 5 6 7 8))
(1 3 5 7)
-> (remove-multiples-too 3 '(3 3 3 9 5 6 7 8))
(5 7 8)

-> (cdr* '((a b c) (d e) (f)))
((b c) (e) ())
-> (cdr* '(((a) b c) (d (e)) (f ((g) h))))
((b c) ((e)) (((g) h)))

-> (max* '(1 2 3))
3
-> (max* '(3 2 1))
3
-> (max* '(1 3 2))
3
-> (max* '(1))
1

-> (sum '(-1 0 1))
0
-> (sum '(-1 -2 -3))
-6

-> (product '(1 2 3 4))
24
-> (product '(2 3 4 0))
0
-> (product '(3 2 1))
6

-> (append '(a b) '(c d))
(a b c d)
-> (append '(a (b)) '((c d)))
(a (b) (c d))

-> (add-to-end 'a '(b c d))
(b c d a)
-> (add-to-end '(a) '(b c d))
(b c d (a))

Hint--use a lambda.

-> ((mkpairfn 'a) '(() (b c) (d) ((e f))))
((a) (a b c) (a d) (a (e f)))

How to Turn in Your Program

Email the eight program files, remove-multiples-too, cdr*, max*, sum, product, append, add-to-end, and mkpairfn to mailto:jones@cs.ua.edu?subject=CS603MP2jones@cs.ua.edu with a subject line of CS603MP2. If it all possible, try to send this from the email account you placed on the index card. In any case, be sure that your name is included in both program source files and in the body of your email message.

About this document ...

MP2
CS603 Organization of Programming Languages
Due 12 March 2003

This document was generated using the LaTeX2HTML translator Version 2K.1beta (1.61)

Copyright © 1993, 1994, 1995, 1996, Nikos Drakos, Computer Based Learning Unit, University of Leeds.
Copyright © 1997, 1998, 1999, Ross Moore, Mathematics Department, Macquarie University, Sydney.

The command line arguments were:
latex2html -split 0 -nonavigation MP2.tex

The translation was initiated by on 2003-03-04


2003-03-04