3460:430/530              Theory of Programming Languages                                  Fall 2005

Dr. C.-C. Chan                                                                                                                                   Due:  11/20/05

Project #4  (30 pts)

 

Problem:  Write the following lisp functions

 

  1. Write a lisp function count-zeros that takes a simple list of numbers and returns the number of zeros in the list.

 

  1. Write a lisp function count-all-zeros that takes a simple or nested list of numbers and returns the number of zeros in the list.

 

 

  1. Write a lisp function mysort that takes a simple list of integers and returns a sorted list in ascending order.

 

  1. Use the mysort function to write a lisp function mymerge that merge two simple lists of numbers in ascending order.  For example,

(mymerge '(1 3 5 7) '(2 4 6))  returns  (1 2 3 4 5 6 7)

Don't use the built-in merge, sort, or insert functions.  The merge time should be proportional to the length of the longer of the two lists.

 

  1. Write a lisp predicate function equal-struct that tests for the structural equality of two given lists.  Two lists are structurally equal if they have the same list structure, although their atoms may be different.

 

6.   Write a lisp function sumset that takes a positive integer N and a list of positive integers L, determine if there is any set of elements in L whose sum is N.  If there is, return a list of those elements; if not, return nil.  For example,
(sumset  21  '(5 7 12 3 8)) returns nil
(sumset  20 '(5  7  12  3  8)) could return (5  12  3), (5  7  8), or (12  8)


 

Notes:

         You must use the same function names as given in the problems indicated by boldface names.

 

Submissions:

1.  Name your source file “YourLastName.lisp”.

2.  Send the source file by e-mail to sk39@uakron.edu   and chan@cs.uakron.edu

3.  The project is due by midnight of the due day.