Due date: 9/23
The goal of this problem set is to help you design domain-specific
functions, functions that deal with enumerations and unions, functions
that deal with
structs, and functions that have it all.
HtDP: 4.2.1, 4.4.1, 5.1.2, 6.3.1, 6.4.1, 6.5.1, 7.2.1, 7.2.2
Note 1: You must use DrScheme's HtDP Beginning Student
Language (BSL) and the Universe teachpack to solve the problems.
Note 2: Changes to "constants" in your solutions should
have no side effects on the workings of your program (especially your test
A rocket accelerates at 5 meters per square-clock tick like this:
|after t =
Your first task is to design the function
given a number of clock ticks, computes the y coordinate of the rocket.
Your second task is to create the image of a rocket using the primitive
operations of BSL. Keep it simple!
Your third task is to design the function
given a number of clock ticks, creates a scene of the rocket whose center
point has gotten as many pixels from the bottom border as
yy dictates. As far as the
x coordinate is
concerned, keep the rocket exactly in the middle.
Hint: You should tabulate the first few elements of
to-image just like we tabulated the first few elements of
yy for you. Paper and pencil is enough; no need to turn
in this table.
Design a Universe program that graphically illustrates a finite-state machine for
accepting strings of the shape
"a" followed by an arbitrary number of
"c" followed by
"d" over the alphabet
of 26 lowercase letters in the English alphabet.
Your program should discard all key events of length greater than
The initial state should be a 100 by 100 white rectangle. Once your
program has seen an
"a", it should display a 100 x 100 yellow
rectangle. It sticks with yellow until a
"d" is entered, at
which point it switches the color of the rectangle to green and stops to
work. If at any point some unacceptable letter is entered, the program
should display a red rectangle of 100 by 100 pixels and go into a final
- Here is a data definition for the class of all
the necessary structure definitions:
(define-struct pls (x y))
(define-struct mul (x y))
;; Expr is one of:
;; -- (make-pls Number Number)
;; -- (make-mul Number Number)
;; interp. a
pls struct represents an addition,
;; and a
mul struct represents a multiplication
Design a program that renders an
Exprs as an image. The main
function must consume an
Expr and a boolean flag. It produces
an image of the given
Expr; the boolean flag determines whether the
Expr should be rendered as a prefix expression or an infix
Domain knowledge: Use parentheses to surround the
Exprs, no matter whether they are in prefix or
infix notation. The operator should be separated from operands by one
"string space", and the operands should be separated from other operands
or the operator via such a space. There is no need to separate the
parentheses from either the operands to operators. All text is rendered
as 11pt and black.
Design a world program that acts as a one-line editor. The program should
allow you and even your grandmother to enter and edit one line of text.
Editing means changing existing text, perhaps by deleting a character or by
adding another one to the end of the existing text, in the middle, or even
the beginning. Your grandmother should also be able to navigate the text
via arrow keys.
The project is explained in detail in
(Chapter: Adding Structure).