Programming Assignment 2
CSE 130 (Summer 2004)
DUE Wednesday, July 28, before midnight
Functional Programming
In this assignment you will write several functions in Common Lisp. Put
your solutions in a single file called "pa2.cl". To turn it in, run the
following command on on ieng9: "turnin -c cs130u pa2.cl".
1. Suppose sets are implemented as lists where each element of a set
appears exactly once in its list. Define and implement the following
functions:
a. (member? element set) => a true (non-NIL) value
if (equal element x) for some x in set
NIL otherwise
b. (union-of set1 set2) => the union of set1 and set2
2. For a given list l of integers, let (mag l) denote their sum. Define
the function (add-mag-to-each l) to return a new list with (mag l)
added to each element.
3. An integer n is prime if for all i, 2 <= i <= n-1, n MOD i <> 0,
where the MOD operator returns the remainder after integer division.
a. Define
(f n m) => T if for all i, 2 <= i <= m, n MOD i <> 0
NIL otherwise
b. In terms of f, define
(prime n) => T if n is prime
NIL otherwise