## CSci 1301: Problem Set 4

#### Due: Wednesday, September 30 at 11:59pm by e-mail

Please follow the notations described in section 2.5: for each function please write a contract, a purpose, examples, and tests with expected values (drawing functions don't need test cases or examples, but still need a contract and a purpose). Also please write data definitions for structures, i.e. specify the types of all the fields.

### Problem 1 (25 points)

The hangman problem, i.e. exercises 6.7.1, 6.7.2, and 6.7.3 in Section 6.7. Some important notes:

• Read the entire section carefully before you start working. As you work on the problem set, revisit the section frequently to make sure that you are following the guidelines.
• Ex. 6.7.1: The first drawing in Figure 15 is the result of
``````
(draw-next-part 'noose)
``````
The second one is the result of a sequence
``````
(draw-next-part 'noose)
(draw-next-part 'body)
(draw-next-part 'right-arm)
(draw-next-part 'left-arm)
``````
The third one is the result of all 7 calls.
• Ex. 6.7.2. You need to define a structure called `word` that contains three letters (as symbols). Assuming that the first letter field is called `letter1`, one of your test examples may be:
``````
(word-letter1 (make-word 's 'u 'n))
;; expected value
's
``````
Note that it's up to you how you call the three fields, but the structure itself must be called `word`.
• Ex. 6.7.3. The function `reveal` must work with the test examples in the book.
Hint: it is much easier to write `reveal` if your top-level operation in the function is `make-word`. Then you just need to figure out each letter according to the given rules (use conditionals). Writing helper functions would make the task easier.
When you are done, import the teachpack hangman.ss and play the game by evaluating
``````
(hangman make-word reveal draw-next-part)
``````

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.