<html>
<title>Homework 5: Mutual Recursion</title>

<body> 
<h2>
<p align="center">
COMP 210, Spring 2001 <br />
Homework 5 : Mutual Recursion <br />
<font size="-2">Due Oct.03 (wed), in class</font>
</p>
</h2>





<p>
All problems will require all (applicable) steps
from the design recipe, including a template.
Before you tackle the homework, remind yourself of our 
<a href = "/~comp210/Handouts/advice.html">General Advice</a>,
<a href = "/~comp210/Handouts/homework-laws.html">Advice on Homeworks</a>
(in particular: 
<a href="/~comp210/Handouts/homework-laws.html#name-and-staple">staple</a>
and
<a href="/~comp210/Handouts/homework-laws.html#provide-questions">provide
 questions</a>),
and the 
<a href = "/~comp210/Handouts/gradeGuide.html">Grading Guidelines</a>.
</p>

<hr />


<comment>
<li>(5 pts)
Two functions which process a list-of-symbols and a NatNum:
<ol type="a">
<li>
Write <tt>remove&lt;=n</tt>,
which takes in a list of symbols, a NatNum, and a symbol,
and returns a list like the input,
but missing n occurrences of the target symbol.
If there were fewer than n occurrences,
then it returns the input less all occurrences.
</li>
<li>
Write <tt>remove=n</tt>,
which is like remove&lt;=n except that
if there are fewer than n occurrences, return false.
Hint: use a helper function, which processes the
result of the recursive call.
</li>
</comment>










An xexpr ("xml-expression") is either:
<ul>
<li>
a string
<footnote>
A string is text between quotation marks: e.g., <code>"hello"</code>
and <code>"  spaces   Count "</code>.
Strings are built-in primitive types (like numbers and symbols
).
The only string functions you'll need for this assignment are
 <code>string?</code>
and
<code>string=?</code>,
both built-in.
We won't use any of the string-processing functions
you can find mentioned in help-desk 
</footnote>
<footnote>
<p>
The intended difference between strings and symbols is that
strings are used when you may want to look at
individual characters inside the string.
(Indeed, the name refers to "characters that have been strung together".)
We won't use this aspect of strings,
and we'd actually use symbols except that we'll be working with 
web pages, that use strings.
(If curious, see the beginning scheme language manual in helpdesk,
for the string-processing functions.)
</p>
</footnote>
, or
</li>
<li>
(cons <var>symbol</var> <var>xlist</var>)
<comment>
<footnote>
You might be wondering, why not
represent xexprs as its own struct with two entries? -- a tag, and an xlist.
Instead, we piggy-back off the built-in <tt>cons</tt> structure,
to represent xexprs.
Good question.
It probably should be, but for shorthand reasons isn't.
(I.e., using the quote syntax for lists,
it's extremely convenient to write tagged xexprs;
a call to some <tt>make-tagged-expr</tt> isn't required.)
</footnote>
</comment>
where the first symbol is called the "tag".
We'll call this a "tagged expression".
</li>
</ul>


An xlist (list of xexpr) is:
<ul>
<li>
- empty, or
</li>
<li>
- (cons <var>xexpr</var> <var>xlist</var>)
</li>
</ul>




<p>
Do the following:
<ul>
<li>
Make some further examples of xexprs,
for testing our later functions.
</li>
<li>
Write <tt>xexpr=?</tt>,
which takes two xexpressions and dtermines
whether they're equal.
(This wil be helpful when doing your test cases.)
</li>
<li>
Write the function <tt>is-this-a?</tt>,
which takes in a symbol and an xexpr,
and returns whether the xexpr is a list whose
first item is the indicated symbol.
(An easy function, but handy.)
</li>
<li>
strip-comments:
Given 
an xexpr,
return an xexpr w/ any <tt>'comment</tt> sub-xexprs removed.
</li>
<li>
collect-captions:
Given 
an xexpr,
return a list of any sub-exprs with a tag <tt>'caption</tt>.
</li>
<li>
collect-pictures
</li>
<li>
wrap-into-html: xlist --&gt; xexpr
</li>
<li>
frame-picture: xexpr --&gt; xexpr.
Given a picture (ie, a tagged-xexpr with the tag <tt>'picture</tt>),
return ...html with that image.
</li>
<li>
verify-1-tag:
Given a 
xlist
and a symbol,
return true if there is exactly one top-level
tagged-xexpr in the list, with the indicated tag.
This is useful in checking that, say, a picture
contains at exactly one <tt>'caption</tt> tag.
<footnote>
What do we mena by "top-level"?
Note that the list might contain, say, a
table which in turn contains a <tt>'caption</tt> tag;
that's okay.
</footnote>
</li>
<li>
Other possibilities:
trim-all-strings, or contains-string, 
or contains-tag, or count-tags, or verify-1-tag ...
</li>
</ul>
</p>




<footnote>
<p>
This assignment will just create files in your the current directory -- that
is, the one in which you started drscheme.
If, for your own fun, you want to refer to files in other
directories, see helpdesk "filesystem utilities",
with platform-independent functions like <code>build-path</code>.
</p>
</footnote>


<p>
We will use the teachpack
<tt>xexpr</tt>,
which exports the following functions:
<ul>
<li> url-&gt;xexpr 
</li>
<li> file-&gt;xexpr
</li>
<li> xexpr-&gt;file
</li>
<li> current-date-string
</li>
</ul>
</p>

</body>
</html>
