Assignment 3

CS 152
due April 5, 1999
100 points

Test the functions below using at least the test cases in the function test, which may be found in the file a3test.drs at the class web site.

(a) (15 points) Write a predicate all-real? that returns #t if and only if all of the top-level members of its argument are real. You may assume that this argument is a list.

(b) (15 points) Write a function remove-nonreal that returns the list obtained by removing all top-level members of the argument list that are not real. You may assume that this argument is a list.

(c) (15 points) Write a function where-is-max that finds the position in the list of the largest of a list of numbers. You may assume that the single argument is a list of numbers. List positions should be numbered beginning with 0. In case of ties, you need only return the position of one of the largest elements.

(d) (15 points) Write a function where-is-max-value that takes a list of numbers and a function, and finds the position in the list of the element giving the largest function value. You may assume that the first argument is a list of numbers, and that the second is a real-valued function of a real number. Number list positions and handle ties as in part (c).

(e) (40 points) Implement a data type wordlist that stores the present tense (non-third-singular), past tense, and past participle of English verbs. Define a variable empty-wordlist, a predicate empty-wordlist?, and functions find-past-from-pres, find-pres-from-past, find-part-from-pres, and find-pres-from-part, that will convert the present tense form to or from any of the others. Also define a function make-entry that will create an entry in the wordlist given 3 forms (as symbols) and a function add-entry that will take such an entry and a wordlist and return a new wordlist consisting of the old wordlist updated by the addition of the entry.

In all parts, you may define whatever auxiliary functions you want. You needn't define your functions recursively if you can define them in terms of Scheme primitive functions.