Teaching
211 F '06
 
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
Set 13
Set 14

Problem Set 7

Due date: 10/26 @ 6pm

Programming Language: Begnning Student Language with List Abbreviations

Teachpacks: world.ss

Problem 0 [5%]:

Find one interesting article from the weeks news on the use of software/computers in society. Summarize the article in your own words with a single 200-word paragraph, as a pair, one playing writer, the other playing editor. Add both the article and the summary in with the rest of your problem set.


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, 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.4, 14.1.6, 14.2.1, 14.2.2, 14.2.3, 14.2.4, 17.6.4, 17.6.6

Problem A1:

XML is a modern language (really: a family of languages) for encoding data. It uses "named parentheses" to group structured data and strings for everything else. [Well, it contains a few more things than that, but this is good enough for now.] Here is an example:


  <p><b>Problem A1</b>:</p>

  <blockquote>
    <p>XML is a modern language (really: a family of
      languages) for encoding data. It uses "named
      parentheses" to group structured data and strings for
      everything else. [Well, it contains a few more things
      than that, but this is good enough for now.] 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>

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 Problem A1. It misses this paragraph and it misses something in the middle. Nevertheless, it is a good example of the kind of XML you will encounter in the real world.

There are many ways to represent XML data in Scheme. Here is one of them:


  An Xexpr is one of: 
  -- (cons Symbol LoXexpr)
  -- String 

  A LoXexpr is one of: 
  -- empty 
  -- (cons Xexpr LoXexpr)

Interpretation: An Xexpr 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 XML and 50 years older than XML, but people don't like parentheses. They are soooooo ugly.)

In this context solve the following problems:

  1. Translate the XML example from above into an Xexpr.
  2. Design a function that counts the number of symbols in an Xexpr.
  3. Design a function that counts the number of characters in an Xexpr.


last updated on Thu Nov 30 11:55:15 EST 2006generated with PLT Scheme