88 lines
2.9 KiB
HTML
88 lines
2.9 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
|
|
<!Originally converted to HTML using LaTeX2HTML 95 (Thu Jan 19 1995) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
|
|
<HEAD>
|
|
<TITLE> Exercises</TITLE>
|
|
</HEAD>
|
|
<BODY>
|
|
<meta name="description" value=" Exercises">
|
|
<meta name="keywords" value="lp">
|
|
<meta name="resource-type" value="document">
|
|
<meta name="distribution" value="global">
|
|
<P>
|
|
<BR> <HR>
|
|
<A HREF="node50.html"><IMG ALIGN=BOTTOM ALT="next" SRC="next_motif.gif"></A>
|
|
<A HREF="node41.html"><IMG ALIGN=BOTTOM ALT="up" SRC="up_motif.gif"></A>
|
|
<A HREF="node48.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif"></A> <BR>
|
|
<A HREF="lp.html"><B>Contents</B></A>
|
|
<B> Next:</B>
|
|
<A HREF="node50.html"> Simple Data Structures </A>
|
|
<B>Up:</B>
|
|
<A HREF="node41.html"> Programming Techniques</A>
|
|
<B> Previous:</B>
|
|
<A HREF="node48.html"> Summary of Rules</A>
|
|
<BR> <HR> <P>
|
|
<H1> Exercises</H1>
|
|
<P>
|
|
<DL COMPACT><DT>1.
|
|
<DD> Write a function called ``b-remove'' (for better remove), which
|
|
takes a list and an element as arguments, and returns the original
|
|
list with all occurrences of the element removed.
|
|
<P>
|
|
<DT>2.
|
|
<DD> Write a function called ``replace,'' which takes a list and two
|
|
elements as arguments, and returns the original list with all
|
|
instances of the first element replaced by the second element.
|
|
<P>
|
|
<DT>3.
|
|
<DD> Write a function which counts all of the atoms in a nested list.
|
|
<P>
|
|
<DT>4.
|
|
<DD> Write a function called ``insert,'' which takes a nested list and
|
|
two atoms as arguments, and returns the original list in which
|
|
the second atom has been inserted to the right of all occurrences of
|
|
the first atom (if the first atom occurs in the list at all).
|
|
<P>
|
|
<DT>5.
|
|
<DD> A new mathematical, binary operator $ is defined as follows:
|
|
<P>x $ y = x<sup>2</sup> + y
|
|
<p>
|
|
where <b>x</b>, <b>y</b> are integers. Extend the definition of ``evaluate''
|
|
presented earlier to include the operators $ and / (normal
|
|
division).
|
|
<P>
|
|
<DT>6.
|
|
<DD> The Fibonacci series is defined as follows:
|
|
<BLOCKQUOTE>
|
|
<PRE><tt>
|
|
fib(n) = {fib(n-1) + fib(n-2) if n> 1 }
|
|
{1 if n=0 or n=1}
|
|
|
|
<P>
|
|
Implement a recursive function to calculate the <b>nth</b> fibonacci
|
|
number.
|
|
<P>
|
|
<DT>7.
|
|
<DD> Write a function called ``merge,'' which takes two number-lists
|
|
of equal length. It adds the corresponding members of each list
|
|
and then returns the product of the resulting numbers.
|
|
<P>
|
|
For example, <code>(merge '(1 2 3) '(2 2 2))</code> should return 60, since
|
|
(1+2)*(2+2)*(3+2)=60.
|
|
<P>
|
|
<DT>8.
|
|
<DD> Will the following piece of code always terminate? Be careful to
|
|
consider all possible cases.
|
|
<BLOCKQUOTE>
|
|
<PRE> (defun mystery (n)
|
|
(cond ((= n 0) 0)
|
|
(t (mystery (- n 1)))))
|
|
</PRE>
|
|
</BLOCKQUOTE>
|
|
<P>
|
|
</DL><BR> <HR>
|
|
<P>
|
|
<ADDRESS>
|
|
<I>© Colin Allen & Maneesh Dhagat <BR>
|
|
March 2007 </I>
|
|
</ADDRESS>
|
|
</BODY>
|