CS
4850 - Programming Languages
HW2 - Lisp
SummerII
2007
Given: July 13, 2007
Due July 20, 2007 (1:30pm)
This assignment
will help you get practice on writing programs in Lisp. Use clisp on cs
machines for your implementations.
1. Write a lisp function that
averages its three rguments, first
checking to see that they are numbers; if they are not, have
the function AVERAGE return 'error.
2. Write a lisp function QUADRATIC of three arguments A, B, and C
which returns a root of the quadratic equation
A z^2 - B z - C = 0.
For example, (QUADRATIC 1
-2 3) would return either -3 or 1.
3. Modify the function QUADRATIC to the function QUADRATICL so that
the new function returns the largest root.
4. The Euclidean norm of a vector (x1, x2 , x3, ..., xn) of length n is
defined as sqrt((x1)^2 + (x2)^2 + ... + (xn)^2)). Suppose we represent
a
vector (x1, x2 , x3, ..., xn) as an n-element list (x1 x2 x3 ... xn).
Write a function
EUCLIDEAN_NORM that returns the norm of its input argument vector. Assume
that the maximum length of the vector is 25.
5. If you are distressed that
the names CAR and CDR are non-mneumonic,
you are now in a position to do something about it. Define functions
MYFIRST and MYREST that behave exactly like CAR and CDR, respectively.
6. Write a recursive lisp function
COUNT-ATOMS that counts the
number of non-nil atoms that appear at all levels of a list. For
example, (COUNT-ATOMS '(a (b ((c))) (d (e) f))) returns 6.
7 . Write a recursive function REPLACE_ALL that replaces all
occurrences of an element from a list. For example,
(REPLACE_ALL '(a x) '(a b (a) c (a d) e)) returns (x b (x) c (x d) e).
8 . Write a lisp predicate NON-MEMBER that returns true if
the value of its first argument does NOT occur in the
value of its second.
For example, (NON-MEMBER 'a '(b a c a)) should return false,
while (NON-MEMBER 'a '(b c d)) should return true.
Penalty for Late Submission
10% per day (including weekends).
Turn in programs at the start of class when due.
Any student may be asked to
show and discuss his solution in class, so be ready with your presentation.
For programming assignments (i) email me a zipped file of your source
codes, scripts (to run your program) and report, and (ii) submit a hardcopy
of your source codes, scripts, a couple of sample executions of your solution
and report.
Use <hw#cs4850_yourlastname_mmddyy.{zip,ppt,doc,tex}>
as the naming convention for your zipped, ppt, MS-Word, or LaTex files
when emailing your submission to ajay.gupta@wmich.edu. . Replace '#' with
the appropriate homework number.
REMINDER:
You
are responsible for making yourself aware of and understanding the policies
and procedures in the undergraduate
(pp. 268-270) [Graduate
(pp. 24-26)] Catalog that
pertain to Academic Integrity. Additionally,
easy availability of information, material, source codes, lecture notes
etc on the Internet may make it possible to find solutions to your assignments
on the Internet or elsewhere. It is okay to refer to those, understand
them and use them to enhance your solutions, generate your own ideas etc.
However, you must give proper and full credit to original authors of the
work, if you include their ideas. Failing to do so is part of academic
and professional dishonesty. It will not be tolerated in this class. Do
not give in to temptations....
|