svn: r9439

This commit is contained in:
Matthias Felleisen 2008-04-23 23:04:59 +00:00
parent de717e625d
commit b2e6252d5c
10 changed files with 203 additions and 178 deletions

View File

@ -0,0 +1,45 @@
#lang scribble/doc
@(require scribble/manual
(for-label scheme
teachpack/htdp/arrow-gui))
@title[#:tag "arrow-gui"]{An Arrow GUI: arrow-gui.ss}
@declare-exporting[teachpack/htdp/arrow-gui]
The teachpack provides operations for creating and manipulating an arrow
GUI. We recommend using the @seclink["world"]{world teachpack} instead.
@deftech{modelT} @scheme[(-> button% event% true)]
A @tech{modelT} is a function that accepts and ignores two arguments.
@defproc[(control) symbol?]{Reads out the current state of the message
field.}
@defproc[(view [s (or/c string? symbol?)]) true]{Displays @scheme[s] in the
message field.}
@defproc[(connect [l (unsyntax @tech{modelT})][r (unsyntax @tech{modelT})][u (unsyntax @tech{modelT})][d (unsyntax @tech{modelT})]) true]{Connects four
controllers with the four directions in the arrow window.}
Example:
@(begin
#reader scribble/comment-reader
(schemeblock
;; Advanced
(define (make-model dir)
(lambda (b e)
(begin
(view dir)
(printf "~a ~n" (control)))))
(connect
(make-model "left")
(make-model "right")
(make-model "up")
(make-model "down"))
))
Now click on the four arrows. The message field contains the current
direction, the print-out the prior contents of the message field.

View File

@ -1,34 +0,0 @@
{ (define LIBNAME "Arrows GUI")
(include "head.tinc") }
<p>The teachpack <code>arrow-gui.ss</code> implements three functions:
<menu>
<li> <code>{(idx control)} : -> symbol</code> <br>
to read out the current state of the message field
<li> <code>{(idx view)} : (union string symbol) -> true</code> <br>
to display its argument in the message field
<li> <code>modelT = (button% event% -> true)</code> <br>
<code>{(idx connect)} : modelT modelT modelT modelT -> true</code> <br>
to connect four controllers with the four directions in the arrow window
</menu>
<p>Example:
<pre>
> (define (make-model dir)
(lambda (b e)
(begin
(view dir)
(printf "~a ~n" (control)))))
> (connect
(make-model "left")
(make-model "right")
(make-model "up")
(make-model "down"))
</pre>
Now click on the four arrows. The message field will contain the current
direction, the print-out the prior contents of the message field.
{(include "foot.tinc")}

View File

@ -4,7 +4,7 @@
(for-label scheme
teachpack/htdp/convert))
@title[#:tag "convert"]{Converting Temperaturs: convert.ss}
@title[#:tag "convert"]{Converting Temperatures: convert.ss}
@declare-exporting[teachpack/htdp/convert]

View File

@ -0,0 +1,41 @@
#lang scribble/doc
@(require scribble/manual
(for-label (except-in scheme/base file-size)
teachpack/htdp/dir))
@title[#:tag "dir"]{Working with Files and Directories: dir.ss}
@declare-exporting[teachpack/htdp/dir]
The teachpack provides structures and operations for working with files and
directories:
@defstruct[dir ([name string?][dirs (list-of dir?)][files (list-of file?)])]{}
@defstruct[file ([name string?][content (list-of char?)])]{}
@defproc[(create-dir [path string?]) dir?]{
Turns the directory found at @scheme[path] on your computer into an instance of @scheme[dir?].}
Sample: Set teachpack to <code>dir.ss</code> and click RUN:
@(begin
#reader scribble/comment-reader
(schemeblock
> (create-dir ".")
(make-dir
'|.|
empty
(cons (make-file 'ball1.gif 1289 empty)
(cons (make-file 'blueball.gif 205 empty)
(cons (make-file 'greenbal.gif 204 empty)
(cons (make-file 'redball.gif 203 empty)
(cons (make-file 'ufo.gif 1044 empty)
(cons (make-file 'gif-test.ss 5811 empty)
empty)))))))
))
Using ``.'' usually means the directory in which your program is
located. In this case, the directory contains no sub-directories and six
files.
Note: Softlinks are always treated as if they were empty files.

View File

@ -1,41 +0,0 @@
{ (define LIBNAME "Directories")
(include "head.tinc") }
<p>The teachpack <code>dir.ss</code> provides two-structures and one
operation:
<menu>
<li> <code>(define-struct dir (name dirs files))</code>
<li> <code>(define-struct file (name size content))</code>
<li> <code>{(idx create-dir)}</code> which consumes a directory path (a string)
and produces a directory.
</menu>
<p>The teachpack relies on two data definitions:
<menu>
<li>
A Directory is
<code>({(idx make-dir)} string[path] (listof Directory) (listof File))</code>
<li>
A File is <code>({(idx make-file)} String PositiveNumber (listof Char))</code>
</menu>
Sample: Set teachpack to <code>dir.ss</code> and execute. Then evaluate
<pre>
> (create-dir ".")
(make-dir
'|.|
empty
(cons (make-file 'ball1.gif 1289 empty)
(cons (make-file 'blueball.gif 205 empty)
(cons (make-file 'greenbal.gif 204 empty)
(cons (make-file 'redball.gif 203 empty)
(cons (make-file 'ufo.gif 1044 empty)
(cons (make-file 'gif-test.ss 5811 empty)
empty)))))))
</pre>
<p>Note: Softlinks are always treated as if they were empty files.
{(include "foot.tinc")}

View File

@ -0,0 +1,23 @@
#lang scribble/doc
@(require scribble/manual
(for-label scheme
teachpack/htdp/graphing))
@title[#:tag "graphing"]{Graphing Functions: graphing.ss}
@declare-exporting[teachpack/htdp/graphing]
The teachpack provides two operations for graphing functions in the regular
(upper right) quadrant of the Cartesian plane (between 0 and 10 in both
directions):
@defproc[(graph-fun [f (-> number? number?)][color symbol?]) true]{
Draws the graph of @scheme[f] with the given @scheme[color].}
@defproc[(graph-line [line (-> number? number?)][color symbol?]) true]{
Draws @scheme[line], a function representing a straight line, with a given
color.}
For color symbols, see @secref{draw}.

View File

@ -1,18 +0,0 @@
{ (define LIBNAME "Graphing Functions")
(include "head.tinc") }
The teachpack <code>graphing.ss</code> provides two operations for
graphing functions in the regular (north-east) quadrant of the Cartesian
plane (between 0 and 10 in both directions):
graphics functions:
<menu>
<li><code>{(idx graph-fun)}</code> : (number -> number) symbol -> true; <br>
draws a function in bulletized form with a given color
<li><code>{(idx graph-line)}</code> : (number -> number) symbol -> true (no arguments); <br>
draws a straight-line function with a given color
</menu>
For legal color symbols, see the documentation for the <a href=draw.html>draw.ss</a>
teachpack.
<br>
{(include "foot.tinc")}

View File

@ -0,0 +1,87 @@
#lang scribble/doc
@(require scribble/manual
(for-label scheme
teachpack/htdp/gui))
@title[#:tag "gui"]{Simple Graphical User Interfaces: gui.ss}
@declare-exporting[teachpack/htdp/gui]
The teachpack provides operations for creating and manipulating graphical
user interfaces. We recommend using the @seclink["world"]{world teachpack}
instead.
@deftech{Window} A @tech{Window} is a data representation of a visible
window on your computer screen.
@deftech{GUI-ITEM} A @tech{GUI-Item} is a data representation of an active
component of a window on your computer screen.
@defproc[(show-window [w Window]) true]{Shows @scheme[w].}
@defproc[(hide-window [w window]) true]{Hides @scheme[w].}
@defproc[(create-window [g (listof (listof (unsyntax @tech{GUI-ITEM})))]) Window]{
Creates a window from the ``matrix'' of gui items @scheme[g].}
@defproc[(make-button [label string>][callback (-> event% boolean)]) (unsyntax @tech{GUI-ITEM})]{Creates a
button with @scheme[label] and @scheme[callback] function. The latter
receives an argument that it may safely ignore.}
@defproc[(make-message [msg string?]) (unsyntax @tech{GUI-ITEM})]{Creates a message item from @scheme[msg].}
@defproc[(draw-message [g (unsyntax @tech{GUI-ITEM})][m string?]) true]{Displays @scheme[m]
in message item @scheme[g] and erases the current message.}
@defproc[(make-text [txt string?]) (unsyntax @tech{GUI-ITEM})]{Creates an text editor (with
label @scheme[txt]) that allows users to enter text.}
@defproc[(text-contents [g (unsyntax @tech{GUI-ITEM})]) string?]{
Determines the current contents of a text @tech{GUI-ITEM}.}
@defproc[(make-choice [choices (listof string?)]) (unsyntax @tech{GUI-ITEM})]{
Creates a choice menu from @scheme[choices] that permits users to choose
from some alternatives.}
@defproc[(choice-index [g (unsyntax @tech{GUI-ITEM})]) natural-number/c]{Determines the
choice that is currently selected in a choice @tech{GUI-ITEM}; the result
is the 0-based index in the choice menu}
Example 1:
@(begin
#reader scribble/comment-reader
(schemeblock
> (define w (create-window (list (list (make-button "QUIT" (lambda (e) (hide-window w)))))))
;; A button appears on the screen. Click on the button and it will disappear.
> (show-window w)
;; The window disappears.
))
Example 2:
@(begin
#reader scribble/comment-reader
(schemeblock
;; text1 : GUI-ITEM
(define text1
(make-text "Please enter your name"))
;; msg1 : GUI-ITEM
(define msg1
(make-message (string-append "Hello, World" (make-string 33 #\SPACE))))
;; Event -> true
;; draws the current contents of text1 into msg1, prepended with "Hello, "
(define (respond e)
(draw-message msg1 (string-append "Hello, " (text-contents text1))))
;; set up window with three "lines": a text field, a message, and two buttons
;; fill in text and click OKAY
(define w
(create-window
(list
(list text1)
(list msg1)
(list (make-button "OKAY" respond)
(make-button "QUIT" (lambda (e) (hide-window w)))))))
))

View File

@ -1,77 +0,0 @@
{ (define LIBNAME "GUI")
(include "head.tinc") }
<p>The teachpack <code>gui.ss</code> provides the following operations:
<menu>
<li> <code>{(idx show-window)} : window -> true</code>
<br>to show the window
<li> <code>{(idx hide-window)} : window -> true</code>
<br>to hide the window
<li> <code>{(idx create-window)} : (listof (listof gui-item)) -> window</code>
<br>to add gui-items to a window and to show the window
<br>each list of gui-items defines one row of gui items in the window
<li> <code>{(idx make-button)} : str (event% -> boolean) -> gui-item</code>
<br>to create a button with label and call-back function
<li> <code>{(idx make-message)} : str -> gui-item</code>
<br>to create an item that displays a message
<li> <code>{(idx draw-message)} : gui-item[message%] stri -> true</code>
<br>to display a message in a message item
<br>it erases the current message
<li> <code>{(idx make-text)} : str -> gui-item</code>
<br>to create an item (with label) that allows users to enter text
<li> <code>{(idx text-contents)} : gui-item[text%] -> str</code>
<br>to determine the contents of a text field
<li> <code>{(idx make-choice)} : (listof str) -> gui-item</code>
<br>to create a choice menu that permits users to choose from some
string alternatives
<li> <code>{(idx choice-index)} : gui-item[choice%] -> num</code>
<br>to determine which choice is currently selected in a choice-item
<br>the result is the 0-based index in the choice menu
</menu>
<p>Example 1:
<pre>
> (define w (create-window (list (list (make-button "QUIT" (lambda (e) (hide-window w)))))))
</pre>
A button appears on the screen. Click on the button and it will disappear.
<pre>
> (show-window w)
</pre>
The frame reappears.
<p>Example 2:
<pre>
; text1 : GUI-ITEM
(define text1
(make-text "Please enter your name"))
; msg1 : GUI-ITEM
(define msg1
(make-message (string-append "Hello, World" (make-string 33 #\SPACE))))
; Event -> true
; draws the current contents of text1 into msg1, prepended with "Hello, "
(define (respond e)
(draw-message msg1 (string-append "Hello, " (text-contents text1))))
; set up window with three "lines": a text field, a message, and two buttons
; fill in text and click OKAY
(define w
(create-window
(list
(list text1)
(list msg1)
(list (make-button "OKAY" respond)
(make-button "QUIT" (lambda (e) (hide-window w)))))))
</pre>
{(include "foot.tinc")}

View File

@ -17,15 +17,14 @@
@include-section["hangman.scrbl"]
@include-section["arrow.scrbl"]
@include-section["docs.scrbl"]
@include-section["dir.scrbl"]
@include-section["graphing.scrbl"]
@include-section["gui.scrbl"]
@include-section["arrow-gui.scrbl"]
@;include-section["files-directories.scrbl"]
@;include-section["graphing.scrbl"]
@;include-section["gui.scrbl"]
@;include-section["lookup-gui.scrbl"]
@;include-section["arrows-gui.scrbl"]
@;include-section["guess-gui.scrbl"]
@;include-section["elevator.scrbl"]
@;include-section["Simplified Scheme Web Servlets"
@;include-section["Scheme Web Servlets"
@;include-section["Simplified Scheme Web Servlets"]
@;include-section["Scheme Web Servlets"]
@;include-section["queen.scrbl"]