The goal of this problem set is to practice the creation of abstractions
and the use of existing abstractions. The table on page 313 is your
HtDP: 21.2.1, 21.2.2, 21.2.3
The TAs have requested that you design a small world program for drill
club. They believe that few, if any students, have the ability to present
and justify the design of 'complete' programs.
"Snake" (aka "worm") is another popular computer game from the middle
ages. A worm always has a head and may have a tail---a sequence of
segments. Think of all these things as circle of a fixed size; if you
wish, think of a marker to distinguish the head.
Design a world program that consumes the number of tail segments and that
moves the worm in reaction to key events. Specifically, only the four
arrow keys should move the worm in the specified direction; the "tail" of
the worm--if any--just moves 'along' one segment at a time. One way to
think about movements is to say that the worm's head moves and the tail's
last segment is cut off. Draw images to understand the problem.
You should proceed in two steps. First design the program using a fixed
number of tail segments; specify the fixed number as a constant and ensure
that you can change the constant and the program's test cases still
pass. Second, re-organize your program so that the main function consumes
the number of tail segments.
Note: You must use DrScheme's HtDP Intermediate Student
Language plus Lambda for this problem set.
If the word "edit" looks vague in the above statements, you have either
not read part IV of HtDP or you haven't read it properly. While we will
spend some time on the ideas in this chapter on Monday (10/19) and Tuesday
(10/20), it will not be the focus of the evening.
Problem 4.1 required the design of the functions:
xexpr-depth. Because the description of the input requires
three data definitions, those of you who designed the functions according
to the design recipe came up with three mutually interconnected functions
(plus perhaps some auxiliary functions).
Task 1: Fix all the problems that the code review panels criticized
about these functions.
Task 2: The first step to editing such clusters of functions after
they have been properly designed and corrected is to re-organize
them into a single function, just like the problem statement
(or your boss's request) states for both of the two functions in this
problem. Do so.
The reason for organizing code in this manner is to create an
organizational structure for future readers. If
xexpr-depth occur in the context of a large module or
program that some reader wishes to understand, he may just read the
purpose statement and ignore the internal nest of local functions during a
first pass. This provides a first overview of the module and puts
everything in context. After that, the reader can "drill" down wherever
Task 3: XML experts refer to (the interpretation of) an Xexpr as an
element. Design the function
which consumes an X-expression
x and symbol
extracts a list of all elements whose tag is
t. Note that an
element with tag
t may occur nested inside of some other
element with the same tag.
- Use existing ISL abstractions to "edit" your solution of problem 4.3.
- Use existing ISL abstractions to "edit" your solution of problem 3.4
For each of the above problems, you are free to choose either partner's
code base as the starting point. Your solution must attribute the code to
the original code base. Failure to do so will result in point deductions.
You may not use any other person's code, i.e., collaboration
outside of the current partnership, especially with your former
partner, is considered theft.