strings instead of chars

svn: r14663
This commit is contained in:
Matthias Felleisen 2009-04-29 21:16:34 +00:00
parent 6d08558ab7
commit f7d8270a6c

View File

@ -40,13 +40,14 @@ This @tt{universe.ss} teachpack implements and provides the functionality
The purpose of this documentation is to give experienced Schemers and HtDP
teachers a concise overview for using the library. The first part of the
documentation focuses on @tech{world} programs. Section @secref["world-example"]
presents an illustration of how to design such programs for a simple
domain; it is suited for a novice who knows how to design conditional
functions for symbols. The second half of the documentation focuses on
"universe" programs: how it is managed via a server, how @tech{world}
programs register with the server, etc. The last two sections show how to
design a simple universe of two communicating worlds.
documentation focuses on @tech{world} programs. Section
@secref["world-example"] presents an illustration of how to design such
programs for a simple domain; it is suited for a novice who knows how to
design conditional functions for enumerations, intervals, and unions. The
second half of the documentation focuses on "universe" programs: how it is
managed via a server, how @tech{world} programs register with the server,
etc. The last two sections show how to design a simple universe of two
communicating worlds.
@emph{Note}: For a quick and educational introduction to just worlds, see
@link["http://www.ccs.neu.edu/home/matthias/HtDP/Prologue/book.html"]{How
@ -215,20 +216,26 @@ current world. The clock ticks at the rate of @scheme[rate-expr].}}
@item{A @tech{KeyEvent} represents key board events, e.g., keys pressed or
released.
@deftech{KeyEvent} : @scheme[(or/c char? symbol?)]
@deftech{KeyEvent} : @scheme[string?]
A single-character string is used to signal that the user has hit an alphanumeric
key. Some of these one-character strings may look unusual:
For simplicity, we represent key events with strings, but not all strings
are key events. The representation of key events comes in distinct
classes. First, a single-character string is used to signal that the user
has hit a "regular" key. Some of these one-character strings may look
unusual:
@itemize[
@item{@scheme[" "] stands for the space bar (@scheme[#\space]);}
@item{@scheme["\r"] stands for the return key (@scheme[#\return]);}
@item{@scheme["\t"] stands for the tab key (@scheme[#\tab]); and}
@item{@scheme["\b"] stands for the backspace key (@scheme[#\backspace]).}
]
On rare occasions you may also encounter @scheme["\u007F"], which is the
On rare occasions you may also encounter @scheme["\u007F"], which is the
string representing the delete key (aka rubout).
A string with more than one character denotes arrow keys or other special events,
Second, some keys have multiple-character string representations. Strings
with more than one character denotes arrow keys or other special events,
starting with the most important:
@itemize[
@item{@scheme["left"] is the left arrow;}
@ -272,7 +279,7 @@ A string with more than one character denotes arrow keys or other special events
@scheme["subtract"],
@scheme["decimal"],
@scheme["divide"]}
@item{@scheme["'f1"],
@item{@scheme["f1"],
@scheme["f2"],
@scheme["f3"],
@scheme["f4"],
@ -316,18 +323,16 @@ A string with more than one character denotes arrow keys or other special events
of the call becomes the current world.
Here is a typical key-event handler:
@(begin
#reader scribble/comment-reader
(schemeblock
@schemeblock[
(define (change w a-key)
(cond
[(key=? a-key 'left) (world-go w -DELTA)]
[(key=? a-key 'right) (world-go w +DELTA)]
[(char? a-key) w] ;; to demonstrate order-free checking
[(key=? a-key 'up) (world-go w -DELTA)]
[(key=? a-key 'down) (world-go w +DELTA)]
[(key=? a-key "left") (world-go w -DELTA)]
[(key=? a-key "right") (world-go w +DELTA)]
[(= (string-length a-key) 1) w] (code:comment "to demonstrate order-free checking")
[(key=? a-key "up") (world-go w -DELTA)]
[(key=? a-key "down") (world-go w +DELTA)]
[else w]))
))
]
}
The omitted, auxiliary function @emph{world-go} is supposed to consume a
world and a number and produces a world.
@ -338,20 +343,20 @@ A string with more than one character denotes arrow keys or other special events
@deftech{MouseEvent} : @scheme[(one-of/c 'button-down 'button-up 'drag 'move 'enter 'leave)]
All @tech{MouseEvent}s are represented via symbols:
All @tech{MouseEvent}s are represented via strings:
@itemize[
@item{@scheme['button-down]
@item{@scheme["button-down"]
signals that the computer user has pushed a mouse button down;}
@item{@scheme['button-up]
@item{@scheme["button-up"]
signals that the computer user has let go of a mouse button;}
@item{@scheme['drag]
@item{@scheme["drag"]
signals that the computer user is dragging the mouse;}
@item{@scheme['move]
@item{@scheme["move"]
signals that the computer user has moved the mouse;}
@item{@scheme['enter]
@item{@scheme["enter"]
signals that the computer user has moved the mouse into the canvas area; and}
@item{@scheme['leave]
@item{@scheme["leave"]
signals that the computer user has moved the mouse out of the canvas area.}
]
@ -543,7 +548,7 @@ Second, we must translate the actions in our domain---the arrows in the
(define (click w x y me) ...)
;; control : WorldState @tech{KeyEvent} -> WorldState
;; deal with a key event (symbol, char) @emph{ke}
;; deal with a key event @emph{ke}
;; in the current world @emph{w}
(define (control w ke) ...)
))
@ -1531,7 +1536,7 @@ The final step is to design the ball @tech{world}. Recall that each world
enumeration of two cases:
@(begin #reader scribble/comment-reader
(schemeblock
(schemeblock
;; teachpack: universe.ss
;; WorldState is one of: