{\rtf1\ansi\ansicpg1252\uc1 \deff0\deflang1033\deflangfe1033{\fonttbl{\f0\froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman{\*\falt Thorndale};}{\f29\fswiss\fcharset128\fprq2{\*\panose 020b0604020202020204}Arial Unicode MS;}
{\f30\fswiss\fcharset128\fprq2 @Arial Unicode MS;}{\f76\froman\fcharset238\fprq2 Times New Roman CE{\*\falt Thorndale};}{\f77\froman\fcharset204\fprq2 Times New Roman Cyr{\*\falt Thorndale};}
{\f79\froman\fcharset161\fprq2 Times New Roman Greek{\*\falt Thorndale};}{\f80\froman\fcharset162\fprq2 Times New Roman Tur{\*\falt Thorndale};}{\f81\froman\fcharset177\fprq2 Times New Roman (Hebrew){\*\falt Thorndale};}
{\f82\froman\fcharset178\fprq2 Times New Roman (Arabic){\*\falt Thorndale};}{\f83\froman\fcharset186\fprq2 Times New Roman Baltic{\*\falt Thorndale};}{\f310\fswiss\fcharset0\fprq2 Arial Unicode MS Western;}
{\f308\fswiss\fcharset238\fprq2 Arial Unicode MS CE;}{\f309\fswiss\fcharset204\fprq2 Arial Unicode MS Cyr;}{\f311\fswiss\fcharset161\fprq2 Arial Unicode MS Greek;}{\f312\fswiss\fcharset162\fprq2 Arial Unicode MS Tur;}
{\f313\fswiss\fcharset177\fprq2 Arial Unicode MS (Hebrew);}{\f314\fswiss\fcharset178\fprq2 Arial Unicode MS (Arabic);}{\f315\fswiss\fcharset186\fprq2 Arial Unicode MS Baltic;}{\f318\fswiss\fcharset0\fprq2 @Arial Unicode MS Western;}
{\f316\fswiss\fcharset238\fprq2 @Arial Unicode MS CE;}{\f317\fswiss\fcharset204\fprq2 @Arial Unicode MS Cyr;}{\f319\fswiss\fcharset161\fprq2 @Arial Unicode MS Greek;}{\f320\fswiss\fcharset162\fprq2 @Arial Unicode MS Tur;}
{\f321\fswiss\fcharset177\fprq2 @Arial Unicode MS (Hebrew);}{\f322\fswiss\fcharset178\fprq2 @Arial Unicode MS (Arabic);}{\f323\fswiss\fcharset186\fprq2 @Arial Unicode MS Baltic;}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;
\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;
\red128\green128\blue128;\red192\green192\blue192;}{\stylesheet{\ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \snext0 Normal;}{\*\cs10 \additive Default Paragraph Font;}{
\s15\ql \li0\ri0\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 \fs24\cf1\lang1033\langfe255\cgrid\langnp1033\langfenp255 \snext15 Default;}{\s16\ql \li0\ri0\nowidctlpar\tqc\tx4320\tqr\tx8640\aspalpha\faauto\rin0\lin0\itap0 
\fs24\cf1\lang1033\langfe255\cgrid\langnp1033\langfenp255 \sbasedon15 \snext16 header;}{\*\cs17 \additive \fs24\cf1\lang0\langfe255\langfenp255 Numbering Symbols;}{
\s18\ql \li0\ri0\sb100\sa100\sbauto1\saauto1\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \fs24\lang1033\langfe1033\loch\f29\hich\af29\dbch\af29\cgrid\langnp1033\langfenp1033 \sbasedon0 \snext18 Normal (Web);}}{\info
{\title CS 131 - Intro to Computer Science I - Fall 2002}{\author Sharon Tuttle}{\operator CNRS}{\creatim\yr2002\mo11\dy8\hr2\min23}{\revtim\yr2002\mo11\dy8\hr2\min29}{\printim\yr2002\mo10\dy29\hr9\min52}{\version6}{\edmins6}{\nofpages2}{\nofwords765}
{\nofchars4363}{\*\company CNRS-HSU}{\nofcharsws5358}{\vern8269}}\margt2114 \deftab1250\widowctrl\ftnbj\aenddoc\noxlattoyen\expshrtn\noultrlspc\dntblnsbdb\nospaceforul\hyphcaps0\horzdoc\dghspace120\dgvspace120\dghorigin1701\dgvorigin1984\dghshow0\dgvshow3
\jcompress\viewkind1\viewscale90\nolnhtadjtbl \fet0\sectd \sbknone\linex0\headery1440\sectdefaultcl {\header \pard\plain \s16\ql \li0\ri0\nowidctlpar\tqc\tx4320\tqr\tx8640\aspalpha\faauto\rin0\lin0\itap0 
\fs24\cf1\lang1033\langfe255\cgrid\langnp1033\langfenp255 {\fs16 CS 131 - Homework #9\tab \tab p. }{\field{\*\fldinst {\fs16 \\page}}{\fldrslt {\fs16\lang1024\langfe1024\noproof 1}}}{
\par }{\fs16 Fall 2002
\par }}{\*\pnseclvl1\pnucrm\pnstart1\pnindent720\pnhang{\pntxta .}}{\*\pnseclvl2\pnucltr\pnstart1\pnindent720\pnhang{\pntxta .}}{\*\pnseclvl3\pndec\pnstart1\pnindent720\pnhang{\pntxta .}}{\*\pnseclvl4\pnlcltr\pnstart1\pnindent720\pnhang{\pntxta )}}
{\*\pnseclvl5\pndec\pnstart1\pnindent720\pnhang{\pntxtb (}{\pntxta )}}{\*\pnseclvl6\pnlcltr\pnstart1\pnindent720\pnhang{\pntxtb (}{\pntxta )}}{\*\pnseclvl7\pnlcrm\pnstart1\pnindent720\pnhang{\pntxtb (}{\pntxta )}}{\*\pnseclvl8
\pnlcltr\pnstart1\pnindent720\pnhang{\pntxtb (}{\pntxta )}}{\*\pnseclvl9\pnlcrm\pnstart1\pnindent720\pnhang{\pntxtb (}{\pntxta )}}\pard\plain \s15\qc \li0\ri0\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 
\fs24\cf1\lang1033\langfe255\cgrid\langnp1033\langfenp255 {\b\fs20 CS 131 - Intro to Computer Science I - Fall 2002
\par Homework #9
\par DUE: Friday, November 15th, by }{\b\fs20\ul 5:00 pm}{\b\fs20 
\par }\pard \s15\ql \li0\ri0\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 {\fs20 
\par }\pard\plain \s18\ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \fs24\lang1033\langfe1033\loch\af29\hich\af29\dbch\af29\cgrid\langnp1033\langfenp1033 {\b\af0\fs20 \hich\af0\dbch\af29\loch\f0 
----------------------------------------------------------------------------------------------------------------------------}{
\par }{\b\af0\fs20 \hich\af0\dbch\af29\loch\f0 NOTE: I forgot to mention in \hich\af0\dbch\af29\loch\f0 class 11-7: here are the next two reading assignments:}{
\par }\pard \s18\ql \fi-437\li856\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin856\itap0 {\af0\fs20 \hich\af0\dbch\af29\loch\f0 * \tab Functions working on functions: }{\b\af0\fs20 \hich\af0\dbch\af29\loch\f0 Section 19, pp. 283-298, Section 21.}{

\par }{\af0\fs20 
\par }{\af0\fs20 \hich\af0\dbch\af29\loch\f0 * \tab Structural vs. Generative Recursion: }{
\par }\pard \s18\ql \fi-437\li1293\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin1293\itap0 {\af0\fs20 \hich\af0\dbch\af29\loch\f0 * \tab }{\b\af0\fs20 \hich\af0\dbch\af29\loch\f0 Section 25 intro, pp. 357-358}{
\par }{\af0\fs20 \hich\af0\dbch\af29\loch\f0 * \tab }{\b\af0\fs20 \hich\af0\dbch\af29\loch\f0 Section 25.2}{\af0\fs20 \hich\af0\dbch\af29\loch\f0 , }{\b\af0\fs20 \hich\af0\dbch\af29\loch\f0 pp. 362-368}{
\par }{\af0\fs20 \hich\af0\dbch\af29\loch\f0 * \tab }{\b\af0\fs20 \hich\af0\dbch\af29\loch\f0 Section 26}{\af0\fs20 \hich\af0\dbch\af29\loch\f0 ,}{\b\af0\fs20 \hich\af0\dbch\af29\loch\f0  pp. 368-38\hich\af0\dbch\af29\loch\f0 0}{
\par }\pard \s18\ql \fi-437\li420\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin420\itap0 {\b\af0\fs20 \hich\af0\dbch\af29\loch\f0 
----------------------------------------------------------------------------------------------------------------------------}{
\par }\pard\plain \s15\ql \li0\ri0\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 \fs24\cf1\lang1033\langfe255\cgrid\langnp1033\langfenp255 {\fs20 
\par As always, you will turn in certain function definitions and expressions that you have typed into the DrScheme definitions window and saved into one or more file names ending in }{\b\fs20 .scm}{\fs20  .
\par 
\par The program recipe in effect for this homework is the }{\b\fs20 10-11 version}{\fs20 , which now requires a brief description at the end of each data definition (especially for structures, and if the meaning is not c
lear for "supertype"-style and list-style data definitions). Please let me know if you have any questions about this latest program recipe version.
\par 
\par Mostly, the same general class style guidelines still apply, also:
\par }\pard \s15\ql \fi-435\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {\fs20 *\tab choose meaningful function, parameter, and variable names.
\par *\tab use auxiliary functions whenever they are appropriate.
\par *\tab reuse functions whenever possible and appropriate. If a function has already been defined for a previous problem within the same definitions file, you may simply use it in a later problem's function.
\par *\tab define constant values in your functions as named variables written in all capital letters; for example,
\par \tab (define CRUST-WIDTH 1)
\par *\tab a data definition is not repeated for every function that uses that data; the data definition is only given once in a particular Scheme file.
\par 
\par }{\b\fs20 except}{\fs20 , I'll leave it up to you as to if you want to include a }{\b\fs20 template }{\fs20 for structures or not. (You still must always include data definitions! But, I'll let you decide if the templates are useful. Include them i
f they are, and you may choose not to include them if you wish.)}{\b\fs20 
\par }{\fs20 
\par In particular: please note that a problem may ask you to write a particular function. When it is appropriate, you should also write unspecified auxiliary functions that you decide are useful in writing the specifically-requested function.
\par }{\b\fs20 
\par }{\fs20 1.\tab Do Exercise 12.2.1 from p. 174 of HtDP. To make dealing with date comparisons easier, we'll assume that the date is simply the year of the message (2002, 1999, etc.)
\par }{\b\fs20 
\par }{\fs20 2. \tab Leave}{\b\fs20  all }{\fs20 of your work from question #1,}{\b\fs20  except }{\fs20 
comment it out (remember: DrScheme's Scheme menu, "Comment out with semicolons" command). Now encapsulate, using local, your work for question #1 into two programs: one to sort mail by date, and one to sort mail by name. Bring down your dat
a definitions, contract, purpose, examples, and tests for the "final" encapsulated programs.}{\b\fs20 
\par 
\par }{\fs20 3.\tab Consider, again, question #3 from HW #8:
\par 
\par \tab "First, write a function}{\b\fs20  draw-my-}{\fs20 pic that draws a shape/picture of your choice (you set the color(s), the size, and 
the shape(s) involved) given a position indicating where it should be drawn (That is, this function takes a position as input, and draws the shape/picture you decide at that position. Assume an already-open canvas.) It should return}{\b\fs20  true }{
\fs20 if successful.
\par }\pard \s15\ql \fi-435\li855\ri0\nowidctlpar\aspalpha\faauto\rin0\lin855\itap0 {\b\fs20 \tab }{\fs20 (for example, your shape might be a face, or 3 concentric circles, or colored lines that make a pleasing pattern, or connected rectangles, etc.)
\par }\pard \s15\ql \fi-435\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {\b\fs20 
\par \tab }{\fs20 Next, write a function}{\b\fs20  clear-my-pic }{\fs20 that clears the shape/picture drawn by draw-my-pic, again given a position as input. It, too, should return}{\b\fs20  true }{\fs20 if successful.
\par }{\b\fs20 
\par }{\fs20 \tab Finally, write a function}{\b\fs20  animate-my-pic }{\fs20 that takes two natural numbers }{\b\fs20 how-many}{\fs20  and }{\b\fs20 space-amt}{\fs20  as input, and does a simple "animation" of your shape/picture drawn by }{\b\fs20 draw-my-pic}
{\fs20  by causing it to "bounce around" }{\b\fs20 how-many}{\fs20  times (be drawn and cleared }{\b\fs20 how-many}{\fs20  times), with a "pause" of }{
\par }{\b\fs20 \tab space-amt }{\fs20 seconds between each bounce. It should return}{\b\fs20  true }{\fs20 if all of this was successful.
\par }{\b\fs20 
\par \tab }{\fs20  (That is,}{\b\fs20  (animate-my-pic 4 7) }{\fs20 will cause your shape/picture to be drawn at a
 random location on your canvas (1st), then 7 seconds later it will disappear and be drawn at another location (2nd), then 7 seconds later it will disapper and be drawn at another location(3rd), and 7 seconds later it will disappear and be drawn at anothe
r location(4th), and 7 seconds later it will disappear (and that's it).)"
\par }{\b\fs20 
\par \tab }{\fs20 Now, do this with}{\b\fs20  clear-my-pic }{\fs20 as actually described above, using}{\b\fs20  local }{\fs20 to make this work with}{\b\fs20  animate-my-pic }{\fs20 --- in fact, let's take it further, and use}{\b\fs20  local }{\fs20 
to encapsulate all 3 functions within a single function, while we're at it. (For this one, I will assume that draw-my-pic and clear-my-pic were already designed and tested for HW #8; so, here while their bodies will be included within the }{\b\fs20 local}
{\fs20 , you only have to give contract, purpose, examples, and tests for new encapsulated}{\b\fs20  animate-my-pic.)
\par 
\par 4.\tab }{\fs20 Write a}{\b\fs20  }{\fs20 function}{\b\fs20  repeat-which }{\fs20 which takes a natural number which-elem giving the position of a desired element, a natural number how-many giving  the desired number of repetitions, and
 a list --- it returns a list of the which-elem'th element of the list repeated how-many times. (It should throw an error if which-elem is too big (there are not that many elements in the list); if either of which-elem or how-many is 0, it should simply r
eturn an empty list.)
\par 
\par \tab (repeat-which 3 5 (list 1 'ace 'hi 5 true))
\par \tab would produce (list 'hi 'hi 'hi 'hi 'hi)
\par 
\par \tab You should use several auxiliary functions to make this easier (I used two) --- and, after you have designed and tested these, encapsulate everything for this problem together using}{\b\fs20  local}{\fs20 
. (With some trepidation), I'll only require you to turn in contract, purpose, examples, and tests for the final encapsulated}{\b\fs20  repeat-which }{\fs20 version only.
\par }{\b\fs20 
\par }{\fs20 \tab }{\b\fs20 
\par }\pard \s15\ql \li0\ri0\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 {\b 
\par }}