emacs.d/clones/lisp/colinallen.dnsalias.org/lp/node48.html

124 lines
3.6 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> Summary of Rules</TITLE>
</HEAD>
<BODY>
<meta name="description" value=" Summary of Rules">
<meta name="keywords" value="lp">
<meta name="resource-type" value="document">
<meta name="distribution" value="global">
<P>
<BR> <HR>
<A HREF="node49.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="node47.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="node49.html"> Exercises</A>
<B>Up:</B>
<A HREF="node41.html"> Programming Techniques</A>
<B> Previous:</B>
<A HREF="node47.html"> Abstraction</A>
<BR> <HR> <P>
<H1> Summary of Rules</H1>
<P>
<DL COMPACT><DT>1.
<DD> When recurring on a list, do three things:
<DL COMPACT><DT>a.
<DD> check for the termination condition;
<DT>b.
<DD> use the first element of the list;
<DT>c.
<DD> recur with the ``rest'' of the list.
<P>
</DL>
<DT>2.
<DD> If a function builds a list using ``cons,'' return () at
the terminating line.
<DT>3.
<DD> When recurring on a nested list, do three things:
<DL COMPACT><DT>a.
<DD> check for the termination condition;
<DT>b.
<DD> check if the first element of the list is an
atom or a list;
<DT>c.
<DD> recur with the ``first'' and the ``rest'' of the list.
<P>
</DL>
<DT>4.
<DD> When evaluating an expression, do three things:
<DL COMPACT><DT>a.
<DD> check for the termination condition;
<DT>b.
<DD> identify operator;
<DT>c.
<DD> apply operator to recursive calls on the operands.
<P>
</DL>
<DT>5.
<DD> When building a number value using +, return 0 at the
terminating line. When building a number value using
*, return 1 at the terminating line.
<DT>6.
<DD> When recurring on a number, do three things:
<DL COMPACT><DT>a.
<DD> check for the termination condition;
<DT>b.
<DD> use the number in some form;
<DT>c.
<DD> recur with a changed form of the number.
<P>
</DL>
<DT>7.
<DD> To ensure proper termination do two things:
<DL COMPACT><DT>a.
<DD> make sure that you are changing at least one argument in your
recursive call;
<DT>b.
<DD> make sure that your test for termination looks at the arguments that
change in the recursive call.
<P>
</DL>
<DT>8.
<DD> Two simple cases may occur when changing an argument in
a recursive call:
<DL COMPACT><DT>a.
<DD> if you are using ``rest'' to change an argument which is a list,
use ``null'' in the test for termination;
<DT>b.
<DD> if you are decreasing an argument which is a number, compare
it with 0 in the test for termination.
<P>
</DL>
<DT>9.
<DD> Use ``let'' to reduce the number of function calls.
<P>
<DT>10.
<DD> Encapsulate program fragments into new functions to
improve clarity.
<P>
<DT>11.
<DD> Encapsulate repeated program fragments into new functions
to reduce program size.
<P>
</DL><BR> <HR>
<A HREF="node49.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="node47.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="node49.html"> Exercises</A>
<B>Up:</B>
<A HREF="node41.html"> Programming Techniques</A>
<B> Previous:</B>
<A HREF="node47.html"> Abstraction</A>
<BR> <HR> <P>
<BR> <HR>
<P>
<ADDRESS>
<I>&#169; Colin Allen &amp; Maneesh Dhagat <BR>
March 2007 </I>
</ADDRESS>
</BODY>