| Due date: 2/27 @ 6pm
This problem set continues the study of self-referential unions. Some
of the problems cover functions that process two arguments from
classes with complex (self-referential) data definitions. --- You
must follow the design recipe. The graders will look for data
definitions, contracts, purpose statements, examples/tests, and
properly organized function definitions. For the latter (as before),
you must design templates. You do not need to include the templates
with your homework, however. If you do, comment them out.
HtDP Problems:
14.1.3, 14.1.5, 14.2.2, 14.2.3,
14.2.5 : Be sure to create the requested tests/examples,
17.6.6 : Design both functions, name them DNAPrefix-1
and DNAPrefix-2
Problem A1:
HTML is a modern language used for encoding data, usually used to
encode web-page layout. It (and it's parent XML) uses 'named
parentheses' to group structured data, and strings for everything
else. Here is an
example:
<div>
<p><b>Problem A1</b>:</p>
<blockquote>
<p>HTML is a modern language used for encoding
data, usually used to encode web-page layout. It
(and it's parent XML) uses 'named parentheses' to
group structured data, and strings for everything
else. Here is an example:
</p>
<p> Yes, this example is weird, because it is
self-referential but, hey, you should be used to
this by now.
</p>
</blockquote>
</div>
Yes, this example is weird, because it is self-referential but, hey,
you should be used to this by now.
You should have noticed that the example is not a complete
representation of this Problem description. It misses this paragraph
and some stuff in the middle. Nevertheless, it is a good
example of the kind of HTML/XML you will encounter in the real world.
There are many ways to represent HTML data in Scheme. Here is one of them:
An Hexpr is one of:
-- (cons Symbol LoHexpr)
-- String
A LoHexpr is one of:
-- empty
-- (cons Hexpr LoHexpr)
Interpretation: An Hexpr represents a bracketed pair of
"named parentheses" and whatever is in between, e.g.,
<p>
hello <em>world</em>
</p>
Becomes
(list 'p "hello" (list 'em "world"))
(Yes, S-expressions are more compact than HTML and much older,
but people don't like parentheses; I guess "<>" are prettier?)
In this context solve the following problems:
- Translate the first HTML example from above into an
Hexpr. Don't include the line breaks or extra spaces.
- Create a Template for functions that deal with Hexprs
- Design a function that counts the number of Symbols in
an Hexpr.
- Design a function that translates an Hexpr into a String, which
is the HTML representation of the Hexpr. Hint: You may want
to create a list of Strings from each Hexpr, then
use
string-append to put them all together. The string
doesn't have to include any indentation or line breaks, but must
contain the nested 'tags'
|