Csu211 Sp '08
 
Assignments
The Hand In
The Recipes
The World
Set 1
Set 2
Set 3
Set 4
Set 5
Set 6
Set 7
Set 8
Set 9
Set 10
Set 11
Set 12-X

Problem Set 7

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:

  1. Translate the first HTML example from above into an Hexpr. Don't include the line breaks or extra spaces.
  2. Create a Template for functions that deal with Hexprs
  3. Design a function that counts the number of Symbols in an Hexpr.
  4. 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'


last updated on Fri Apr 4 11:29:56 EDT 2008generated with PLT Scheme