Lots of documentation formatting.
Started as fixing misindented definitions, then more indentations, then a bunch of similar things (square brackets, huge spaces at end-of-lines, etc).
This commit is contained in:
parent
d3d9514b1c
commit
d61eb53686
|
@ -16,8 +16,8 @@
|
|||
|
||||
@(define-syntax-rule (def-ext id)
|
||||
(begin
|
||||
(require (for-label net/sendurl))
|
||||
(define id (racket send-url))))
|
||||
(require (for-label net/sendurl))
|
||||
(define id (racket send-url))))
|
||||
@(def-ext net-send-url)
|
||||
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ Zum Beispiel:
|
|||
(define pos (make-vec3 5 5 3))
|
||||
(define lookat (make-vec3 0 0 0))
|
||||
(define camera
|
||||
(create-camera-matrix pos lookat 70.0 screenWidth screenHeight))
|
||||
(create-camera-matrix pos lookat 70.0 screenWidth screenHeight))
|
||||
(code:comment @#,t{render image})
|
||||
(render-scene screenWidth screenHeight box camera)
|
||||
]
|
||||
|
|
|
@ -175,17 +175,17 @@ black white, white black, and is otherwise ill-defined).
|
|||
rgb?)
|
||||
"black"])
|
||||
void?]{
|
||||
|
||||
|
||||
Colors the entire contents of @racket[viewport] with @racket[color].}
|
||||
|
||||
@defproc[((clear-viewport [viewport viewport?]))
|
||||
void?]{
|
||||
|
||||
|
||||
Whitens the entire contents of @racket[viewport].}
|
||||
|
||||
@defproc[((flip-viewport [viewport viewport?]))
|
||||
void?]{
|
||||
|
||||
|
||||
@tech{Inverts} the entire contents of @racket[viewport].}
|
||||
|
||||
|
||||
|
@ -198,7 +198,7 @@ Copies the content of @racket[source] into @racket[dest].}
|
|||
|
||||
@subsection{Pixels}
|
||||
|
||||
@defproc[((draw-pixel [viewport viewport?])
|
||||
@defproc[((draw-pixel [viewport viewport?])
|
||||
[p posn?]
|
||||
[color (or/c (integer-in 0 299)
|
||||
string?
|
||||
|
@ -208,13 +208,13 @@ Copies the content of @racket[source] into @racket[dest].}
|
|||
|
||||
Colors the pixel in @racket[viewport] at @racket[p].}
|
||||
|
||||
@defproc[((clear-pixel [viewport viewport?])
|
||||
@defproc[((clear-pixel [viewport viewport?])
|
||||
[p posn?])
|
||||
void?]{
|
||||
|
||||
Whitens the pixel in @racket[viewport] at @racket[p].}
|
||||
|
||||
@defproc[((flip-pixel [viewport viewport?])
|
||||
@defproc[((flip-pixel [viewport viewport?])
|
||||
[p posn?])
|
||||
void?]{
|
||||
|
||||
|
|
|
@ -19,16 +19,16 @@
|
|||
|
||||
@(define-syntax-rule (defprocthing* mod id ...)
|
||||
(begin
|
||||
(deflazy mod defprocthing id)
|
||||
...))
|
||||
(deflazy mod defprocthing id)
|
||||
...))
|
||||
|
||||
@(define-syntax-rule (defprocthing id . rest)
|
||||
(defthing id procedure? . rest))
|
||||
|
||||
@(define-syntax-rule (defidform* mod id ...)
|
||||
(begin
|
||||
(deflazy mod defidform id)
|
||||
...))
|
||||
(deflazy mod defidform id)
|
||||
...))
|
||||
|
||||
@; ----------------------------------------
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
@(define-syntax-rule (intro id)
|
||||
(begin
|
||||
(require (for-label racket/cmdline))
|
||||
(define id (racket command-line))))
|
||||
(require (for-label racket/cmdline))
|
||||
(define id (racket command-line))))
|
||||
@(intro racket-command-line)
|
||||
|
||||
@mzlib[#:mode title cmdline]
|
||||
|
|
|
@ -13,12 +13,12 @@
|
|||
@interaction-eval[#:eval etc-eval (require mzlib/etc)]
|
||||
|
||||
@(begin
|
||||
(define-syntax-rule (bind id else-id)
|
||||
(begin
|
||||
(require (for-label scheme/base))
|
||||
(define id (racket lambda))
|
||||
(define else-id (racket else))))
|
||||
(bind base-lambda base-else))
|
||||
(define-syntax-rule (bind id else-id)
|
||||
(begin
|
||||
(require (for-label scheme/base))
|
||||
(define id (racket lambda))
|
||||
(define else-id (racket else))))
|
||||
(bind base-lambda base-else))
|
||||
|
||||
@mzlib[#:mode title etc]
|
||||
|
||||
|
@ -77,11 +77,11 @@ syntax transformers that share helper functions, though
|
|||
(define-syntax-set (let-current-continuation
|
||||
let-current-escape-continuation)
|
||||
(define (mk call-id)
|
||||
(lambda (stx)
|
||||
(syntax-case stx ()
|
||||
[(_ id body1 body ...)
|
||||
(with-syntax ([call call-id])
|
||||
(syntax (call (lambda (id) body1 body ...))))])))
|
||||
(lambda (stx)
|
||||
(syntax-case stx ()
|
||||
[(_ id body1 body ...)
|
||||
(with-syntax ([call call-id])
|
||||
(syntax (call (lambda (id) body1 body ...))))])))
|
||||
(define let-current-continuation/proc
|
||||
(mk (quote-syntax call/cc)))
|
||||
(define let-current-escape-continuation/proc
|
||||
|
@ -156,12 +156,12 @@ corresponding expression are bound to the multiple variables.
|
|||
@examples[
|
||||
#:eval etc-eval
|
||||
(let+ ([val (values x y) (values 1 2)])
|
||||
(list x y))
|
||||
(list x y))
|
||||
|
||||
(let ([x 1])
|
||||
(let+ ([val x 3]
|
||||
[val y x])
|
||||
y))
|
||||
(let+ ([val x 3]
|
||||
[val y x])
|
||||
y))
|
||||
]}
|
||||
|
||||
|
||||
|
|
|
@ -10,11 +10,11 @@
|
|||
@interaction-eval[#:eval kw-eval (require mzlib/kw)]
|
||||
|
||||
@(begin
|
||||
(define-syntax-rule (bind id)
|
||||
(begin
|
||||
(require (for-label scheme/base))
|
||||
(define id (racket lambda))))
|
||||
(bind base-lambda))
|
||||
(define-syntax-rule (bind id)
|
||||
(begin
|
||||
(require (for-label scheme/base))
|
||||
(define id (racket lambda))))
|
||||
(bind base-lambda))
|
||||
|
||||
@mzlib[#:mode title kw]
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
@(begin
|
||||
(define-syntax-rule (bind id)
|
||||
(begin
|
||||
(require racket/match)
|
||||
(define id (racket match))))
|
||||
(require racket/match)
|
||||
(define id (racket match))))
|
||||
(bind racket-match))
|
||||
|
||||
@mzlib[#:mode title match]
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
(only-in racket/sandbox make-module-evaluator)))
|
||||
|
||||
@(begin
|
||||
(define-syntax-rule (bind id)
|
||||
(begin
|
||||
(require (for-label racket/sandbox))
|
||||
(define id (racket make-evaluator))))
|
||||
(bind racket-make-evaluator))
|
||||
(define-syntax-rule (bind id)
|
||||
(begin
|
||||
(require (for-label racket/sandbox))
|
||||
(define id (racket make-evaluator))))
|
||||
(bind racket-make-evaluator))
|
||||
|
||||
@mzlib[#:mode title sandbox]
|
||||
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
(for-label mzlib/sendevent))
|
||||
|
||||
@(begin
|
||||
(define-syntax-rule (bind id)
|
||||
(begin
|
||||
(require (for-label scheme/gui/base))
|
||||
(define id (racket send-event))))
|
||||
(bind mred-send-event))
|
||||
(define-syntax-rule (bind id)
|
||||
(begin
|
||||
(require (for-label scheme/gui/base))
|
||||
(define id (racket send-event))))
|
||||
(bind mred-send-event))
|
||||
|
||||
@mzlib[#:mode title sendevent]
|
||||
|
||||
|
|
|
@ -3,12 +3,13 @@
|
|||
(for-label mzlib/serialize))
|
||||
|
||||
@(begin
|
||||
(define-syntax-rule (bind id id2)
|
||||
(begin
|
||||
(require (for-label racket/serialize))
|
||||
(define id (racket define-serializable-struct))
|
||||
(define id2 (racket define-serializable-struct/versions))))
|
||||
(bind racket-define-serializable-struct racket-define-serializable-struct/versions))
|
||||
(define-syntax-rule (bind id id2)
|
||||
(begin
|
||||
(require (for-label racket/serialize))
|
||||
(define id (racket define-serializable-struct))
|
||||
(define id2 (racket define-serializable-struct/versions))))
|
||||
(bind racket-define-serializable-struct
|
||||
racket-define-serializable-struct/versions))
|
||||
|
||||
@mzlib[#:mode title serialize]
|
||||
|
||||
|
|
|
@ -51,11 +51,11 @@ property.
|
|||
|
||||
@examples[
|
||||
#:eval struct-eval
|
||||
(define-struct/properties point (x y)
|
||||
([prop:custom-write (lambda (p port write?)
|
||||
(fprintf port "(~a, ~a)"
|
||||
(point-x p)
|
||||
(point-y p)))]))
|
||||
(define-struct/properties point (x y)
|
||||
([prop:custom-write (lambda (p port write?)
|
||||
(fprintf port "(~a, ~a)"
|
||||
(point-x p)
|
||||
(point-y p)))]))
|
||||
(display (make-point 1 2))
|
||||
]}
|
||||
|
||||
|
|
|
@ -10,13 +10,13 @@ library provides working versions of @racket[transcript-on] and
|
|||
@racket[transcript-off].
|
||||
|
||||
@(define-syntax-rule (go)
|
||||
(begin
|
||||
(require (for-label mzlib/transcr))
|
||||
(begin
|
||||
(require (for-label mzlib/transcr))
|
||||
|
||||
@deftogether[(
|
||||
@defproc[(transcript-on [filename any/c]) any]
|
||||
@defproc[(transcript-off) any]
|
||||
)]{
|
||||
@deftogether[(
|
||||
@defproc[(transcript-on [filename any/c]) any]
|
||||
@defproc[(transcript-off) any]
|
||||
)]{
|
||||
|
||||
Starts/stops recording a transcript at @racket[filename].}))
|
||||
@(go)
|
||||
|
|
|
@ -3,16 +3,16 @@
|
|||
(for-label mzlib/unit))
|
||||
|
||||
@(begin
|
||||
(define-syntax-rule (bind id)
|
||||
(begin
|
||||
(require (for-label racket/unit))
|
||||
(define id (racket struct))))
|
||||
(bind racket-struct)
|
||||
(define-syntax-rule (bindc id)
|
||||
(begin
|
||||
(require (for-label racket/unit))
|
||||
(define id (racket struct/ctc))))
|
||||
(bindc racket-struct/ctc))
|
||||
(define-syntax-rule (bind id)
|
||||
(begin
|
||||
(require (for-label racket/unit))
|
||||
(define id (racket struct))))
|
||||
(bind racket-struct)
|
||||
(define-syntax-rule (bindc id)
|
||||
(begin
|
||||
(require (for-label racket/unit))
|
||||
(define id (racket struct/ctc))))
|
||||
(bindc racket-struct/ctc))
|
||||
|
||||
@mzlib[#:mode title unit]
|
||||
|
||||
|
|
|
@ -22,22 +22,22 @@
|
|||
base-free-identifier=? base-free-template-identifier=?
|
||||
base-free-transformer-identifier=? base-free-label-identifier=?)
|
||||
(begin
|
||||
(require (for-label scheme/base))
|
||||
(define base-define (racket define))
|
||||
(define base-define-syntax (racket define-syntax))
|
||||
(define base-define-for-syntax (racket define-for-syntax))
|
||||
(define base-define-struct (racket define-struct))
|
||||
(define base-if (racket if))
|
||||
(define base-cond (racket cond))
|
||||
(define base-case (racket case))
|
||||
(define base-top-interaction (racket #%top-interaction))
|
||||
(define base-open-input-file (racket open-input-file))
|
||||
(define base-apply (racket apply))
|
||||
(define base-prop:procedure (racket prop:procedure))
|
||||
(define base-free-identifier=? (racket free-identifier=?))
|
||||
(define base-free-template-identifier=? (racket free-template-identifier=?))
|
||||
(define base-free-transformer-identifier=? (racket free-transformer-identifier=?))
|
||||
(define base-free-label-identifier=? (racket free-label-identifier=?))))
|
||||
(require (for-label scheme/base))
|
||||
(define base-define (racket define))
|
||||
(define base-define-syntax (racket define-syntax))
|
||||
(define base-define-for-syntax (racket define-for-syntax))
|
||||
(define base-define-struct (racket define-struct))
|
||||
(define base-if (racket if))
|
||||
(define base-cond (racket cond))
|
||||
(define base-case (racket case))
|
||||
(define base-top-interaction (racket #%top-interaction))
|
||||
(define base-open-input-file (racket open-input-file))
|
||||
(define base-apply (racket apply))
|
||||
(define base-prop:procedure (racket prop:procedure))
|
||||
(define base-free-identifier=? (racket free-identifier=?))
|
||||
(define base-free-template-identifier=? (racket free-template-identifier=?))
|
||||
(define base-free-transformer-identifier=? (racket free-transformer-identifier=?))
|
||||
(define base-free-label-identifier=? (racket free-label-identifier=?))))
|
||||
@(def-base base-define base-define-syntax base-define-for-syntax base-define-struct
|
||||
base-if base-cond base-case base-top-interaction
|
||||
base-open-input-file base-apply base-prop:procedure
|
||||
|
|
|
@ -110,11 +110,11 @@ Raised for errors when handling cookies.}
|
|||
@subsection{Creating a cookie}
|
||||
|
||||
@racketblock[
|
||||
(let ((c (cookie:add-max-age
|
||||
(let ([c (cookie:add-max-age
|
||||
(cookie:add-path
|
||||
(set-cookie "foo" "bar")
|
||||
"/servlets")
|
||||
3600)))
|
||||
3600)])
|
||||
(print-cookie c))
|
||||
]
|
||||
|
||||
|
|
|
@ -343,7 +343,7 @@ characters, @racket[char-lower-case?] characters, etc.}
|
|||
@(define-syntax-rule (lex-sre-doc)
|
||||
(...
|
||||
(begin
|
||||
(require (for-label parser-tools/lex-sre))
|
||||
(require (for-label parser-tools/lex-sre))
|
||||
|
||||
@defform[(* re ...)]{
|
||||
|
||||
|
@ -417,7 +417,7 @@ characters.}
|
|||
@(define-syntax-rule (lex-v200-doc)
|
||||
(...
|
||||
(begin
|
||||
(require (for-label parser-tools/lex-plt-v200))
|
||||
(require (for-label parser-tools/lex-plt-v200))
|
||||
|
||||
@t{The @racketmodname[parser-tools/lex-plt-v200] module re-exports
|
||||
@racket[*], @racket[+], @racket[?], and @racket[&] from
|
||||
|
|
|
@ -199,19 +199,19 @@ the bounds of the image, returns a transparent color.}
|
|||
[f (-> natural-number/c natural-number/c color?)])
|
||||
image?]{
|
||||
|
||||
Builds an image of the specified size and shape by calling the specified function
|
||||
on the coordinates of each pixel. For example,
|
||||
Builds an image of the specified size and shape by calling the specified
|
||||
function on the coordinates of each pixel. For example,
|
||||
@codeblock|{
|
||||
; fuzz : image -> image
|
||||
(define (fuzz pic)
|
||||
(local [; near-pixel : num(x) num(y) -> color
|
||||
(define (near-pixel x y)
|
||||
(get-pixel-color (+ x -3 (random 7))
|
||||
(+ y -3 (random 7))
|
||||
pic))]
|
||||
(build-image (image-width pic)
|
||||
(image-height pic)
|
||||
near-pixel)))
|
||||
(local [; near-pixel : num(x) num(y) -> color
|
||||
(define (near-pixel x y)
|
||||
(get-pixel-color (+ x -3 (random 7))
|
||||
(+ y -3 (random 7))
|
||||
pic))]
|
||||
(build-image (image-width pic)
|
||||
(image-height pic)
|
||||
near-pixel)))
|
||||
}|
|
||||
produces a fuzzy version of the given picture by replacing each pixel with a
|
||||
randomly chosen pixel near it.}
|
||||
|
@ -268,7 +268,7 @@ size and shape. For example,
|
|||
@codeblock|{
|
||||
; lose-red : num(x) num(y) color -> color
|
||||
(define (lose-red x y old-color)
|
||||
(make-color 0 (color-green old-color) (color-blue old-color)))
|
||||
(make-color 0 (color-green old-color) (color-blue old-color)))
|
||||
|
||||
(map-image lose-red my-picture)}|
|
||||
produces a copy of @racket[my-picture] with all the red leached out,
|
||||
|
@ -286,9 +286,9 @@ Another example:
|
|||
@codeblock|{
|
||||
; apply-gradient : num(x) num(y) color -> color
|
||||
(define (apply-gradient x y old-color)
|
||||
(make-color (min (* 3 x) 255)
|
||||
0
|
||||
(min (* 3 y) 255)))
|
||||
(make-color (min (* 3 x) 255)
|
||||
0
|
||||
(min (* 3 y) 255)))
|
||||
|
||||
(map-image apply-gradient my-picture)}|
|
||||
produces a picture the size of @racket[my-picture]'s bounding rectangle,
|
||||
|
@ -402,12 +402,12 @@ For example,
|
|||
@codeblock|{
|
||||
; bad-gradient : num(x) num(y) -> color
|
||||
(define (bad-gradient x y)
|
||||
(make-color (* 2.5 x) (* 1.6 y) 0))
|
||||
(make-color (* 2.5 x) (* 1.6 y) 0))
|
||||
(build-image 50 30 bad-gradient)
|
||||
|
||||
; good-gradient : num(x) num(y) -> color
|
||||
(define (good-gradient x y)
|
||||
(make-color (real->int (* 2.5 x)) (real->int (* 1.6 y)) 0))
|
||||
(make-color (real->int (* 2.5 x)) (real->int (* 1.6 y)) 0))
|
||||
(build-image 50 30 good-gradient)
|
||||
}|
|
||||
The version using @racket[bad-gradient] crashes because color components must be exact integers.
|
||||
|
@ -462,15 +462,15 @@ its output into a string, which is returned. Especially useful for testing:
|
|||
@codeblock|{
|
||||
; ask : string -> prints output, waits for text input, returns it
|
||||
(define (ask question)
|
||||
(begin (display question)
|
||||
(read)))
|
||||
(begin (display question)
|
||||
(read)))
|
||||
; greet : nothing -> prints output, waits for text input, prints output
|
||||
(define (greet)
|
||||
(local [(define name (ask "What is your name?"))]
|
||||
(printf "Hello, ~a!" name)))
|
||||
(local [(define name (ask "What is your name?"))]
|
||||
(printf "Hello, ~a!" name)))
|
||||
(check-expect
|
||||
(with-io-strings "Steve" greet)
|
||||
"What is your name?Hello, Steve!")}|
|
||||
(with-io-strings "Steve" greet)
|
||||
"What is your name?Hello, Steve!")}|
|
||||
}
|
||||
|
||||
@; @include-section{worlds.scrbl}
|
||||
|
|
|
@ -44,7 +44,7 @@ the resolvers behavior.
|
|||
Returns the path corresponding to the planet package (interpreting the arguments
|
||||
the same way as @racket[planet-module-name-resolver] and @racket[(current-module-name-resolver)]).
|
||||
}
|
||||
|
||||
|
||||
@defproc[(resolve-planet-path [planet-path any/c]) path?]{
|
||||
Returns the path where the file named by the require spec @racket[planet-path] is located in the current installation.
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ The port on the server the client should connect to if
|
|||
@defparam[DEFAULT-PACKAGE-LANGUAGE vers string?]{
|
||||
The package language used when communicating with the server to find
|
||||
which package to download.
|
||||
|
||||
|
||||
Defaults to @racket[(version)].
|
||||
}
|
||||
|
||||
|
@ -180,7 +180,7 @@ The port on the server the client should connect to if
|
|||
with ``raco planet link''.
|
||||
|
||||
}
|
||||
|
||||
|
||||
@defproc[(get-hard-linked-packages)
|
||||
(listof (list/c (and/c path? absolute-path?) string? string? (listof string?)
|
||||
exact-nonnegative-integer?
|
||||
|
@ -229,7 +229,6 @@ The @racket[pkg] argument must end with @racket[".plt"].
|
|||
}
|
||||
|
||||
|
||||
|
||||
@defproc[(get-package-spec [owner string?]
|
||||
[pkg (and/c string? #rx"[.]plt$")]
|
||||
[maj (or/c #f natural-number/c) #f]
|
||||
|
@ -278,13 +277,14 @@ the output file's name.
|
|||
|
||||
See also @racket[build-scribble-docs?] and @racket[force-package-building?]
|
||||
}
|
||||
|
||||
|
||||
@defparam[build-scribble-docs? b boolean?]{
|
||||
Determines if @racket[make-planet-archive] builds scribble docs (or not).
|
||||
Determines if @racket[make-planet-archive] builds scribble docs (or not).
|
||||
}
|
||||
|
||||
@defparam[force-package-building? b boolean?]{
|
||||
Determines if @racket[make-planet-archive] is more strict and thus aborts more often.
|
||||
Determines if @racket[make-planet-archive] is more strict and thus
|
||||
aborts more often.
|
||||
}
|
||||
|
||||
@defproc[(download-package [pkg-spec pkg-spec?])
|
||||
|
@ -300,7 +300,7 @@ See also @racket[build-scribble-docs?] and @racket[force-package-building?]
|
|||
a list, then the server is saying that there is no matching package;
|
||||
otherwise the error is some lower-level problem (perhaps no networking, etc.)
|
||||
}
|
||||
|
||||
|
||||
@defproc[(pkg->download-url [pkg pkg?]) url?]{
|
||||
Returns the url for a given package.
|
||||
}
|
||||
|
@ -412,13 +412,14 @@ produces a list corresponding to its name and version, exactly like
|
|||
@racket[(this-package-version)]. Given any other path, produces @racket[#f].
|
||||
|
||||
}
|
||||
|
||||
|
||||
@defstruct[(exn:fail:planet exn:fail) ([message string?] [continuation-marks continuation-mark-set?])]{
|
||||
This exception record is used to report planet-specific exceptions.
|
||||
}
|
||||
|
||||
@defproc[(pkg? [v any/c]) boolean?]{
|
||||
Determines if its argument is a pkg, the representation of an installed package.
|
||||
@defproc[(pkg? [v any/c]) boolean?]{
|
||||
Determines if its argument is a pkg, the representation of an
|
||||
installed package.
|
||||
}
|
||||
|
||||
@section[#:tag "version.rkt"]{Package Version}
|
||||
|
@ -488,7 +489,7 @@ with Scribble to associate each documented binding with the appropriate package.
|
|||
Returns a symbol representing the require spec for @racket[ver],
|
||||
as a planet package.
|
||||
}
|
||||
|
||||
|
||||
@section[#:tag "syntax.rkt"]{Macros and Syntax Objects}
|
||||
|
||||
@defmodule[planet/syntax]
|
||||
|
|
|
@ -181,15 +181,15 @@ function, we could do the following:
|
|||
#:segments [segments 20]
|
||||
#:color [color 'red]
|
||||
#:width [width 1])
|
||||
(let* ((dash-size (/ (- x-max x-min) segments))
|
||||
(x-lists (build-list
|
||||
(let* ([dash-size (/ (- x-max x-min) segments)]
|
||||
[x-lists (build-list
|
||||
(/ segments 2)
|
||||
(lambda (index)
|
||||
(x-values
|
||||
(/ samples segments)
|
||||
(+ x-min (* 2 index dash-size))
|
||||
(+ x-min (* (add1 (* 2 index))
|
||||
dash-size)))))))
|
||||
dash-size)))))])
|
||||
(lambda (2dview)
|
||||
(send 2dview set-line-color color)
|
||||
(send 2dview set-line-width width)
|
||||
|
|
|
@ -399,7 +399,7 @@ Dispatching-related bindings:
|
|||
|
||||
@racketblock[
|
||||
(define (ttref)
|
||||
(let ((url (get-arg)) (text (get-arg)))
|
||||
(let ([url (get-arg)] [text (get-arg)])
|
||||
(list "<a href=\"" url "\">@tt{" text "}</a>")))
|
||||
]
|
||||
|
||||
|
|
|
@ -247,8 +247,8 @@ Here's the implementation of @racket[fold-test-results] in terms of
|
|||
kid-seed)
|
||||
(lambda (case name action seed)
|
||||
(case-fn
|
||||
(run-test-case name action)
|
||||
seed))
|
||||
(run-test-case name action)
|
||||
seed))
|
||||
seed
|
||||
test))
|
||||
]
|
||||
|
|
|
@ -76,7 +76,7 @@ cases. Here's a simple test case written using the
|
|||
|
||||
@racketblock[
|
||||
(test-begin
|
||||
(let ((lst (list 2 4 6 9)))
|
||||
(let ([lst (list 2 4 6 9)])
|
||||
(check = (length lst) 4)
|
||||
(for-each
|
||||
(lambda (elt)
|
||||
|
@ -111,7 +111,7 @@ we're testing. We can give a test case a name with the
|
|||
@racketblock[
|
||||
(test-case
|
||||
"List has length 4 and all elements even"
|
||||
(let ((lst (list 2 4 6 9)))
|
||||
(let ([lst (list 2 4 6 9)])
|
||||
(check = (length lst) 4)
|
||||
(for-each
|
||||
(lambda (elt)
|
||||
|
@ -133,7 +133,7 @@ group them into a test suite:
|
|||
|
||||
(test-case
|
||||
"List has length 4 and all elements even"
|
||||
(let ((lst (list 2 4 6 9)))
|
||||
(let ([lst (list 2 4 6 9)])
|
||||
(check = (length lst) 4)
|
||||
(for-each
|
||||
(lambda (elt)
|
||||
|
|
|
@ -1127,7 +1127,7 @@ For example, the following defines addition on natural numbers:
|
|||
[(sum z n n)]
|
||||
[(sum (s n_1) n_2 (s n_3))
|
||||
(sum n_1 n_2 n_3)])]
|
||||
|
||||
|
||||
The @racket[judgment-holds] form checks whether a relation holds for any
|
||||
assignment of pattern variables in output positions.
|
||||
@examples[
|
||||
|
@ -1199,7 +1199,7 @@ one.
|
|||
(judgment-holds (all-even (z (s (s z)) (s z))))]
|
||||
|
||||
Redex evaluates premises depth-first, even when it doing so leads to
|
||||
non-termination. For example, consider the following definitions:
|
||||
non-termination. For example, consider the following definitions:
|
||||
@interaction[
|
||||
#:eval redex-eval
|
||||
(define-language vertices
|
||||
|
@ -1241,7 +1241,7 @@ the pattern variables in @racket[judgment-id]'s output positions. In its second
|
|||
form, produces a list of terms by instantiating the supplied term template with
|
||||
each satisfying assignment of pattern variables.
|
||||
See @racket[define-judgment-form] for examples.
|
||||
}
|
||||
}
|
||||
|
||||
@defidform[I]{
|
||||
Recognized specially within @racket[define-judgment-form], the @racket[I] keyword
|
||||
|
@ -1294,7 +1294,7 @@ the same inputs, and their results are cached, unless
|
|||
relation is called with the same inputs twice, then its right-hand
|
||||
sides are evaluated only once.
|
||||
}
|
||||
|
||||
|
||||
@defparam[current-traced-metafunctions traced-metafunctions (or/c 'all (listof symbol?))]{
|
||||
|
||||
Controls which metafunctions are currently being traced. If it is
|
||||
|
@ -1638,7 +1638,7 @@ term that does not match @racket[pattern].}
|
|||
(printf "~s\n" (term (number ...)))
|
||||
#:attempts 3
|
||||
#:source R))
|
||||
|
||||
|
||||
(redex-check
|
||||
empty-lang
|
||||
number
|
||||
|
@ -2284,8 +2284,8 @@ Like @racket[render-metafunction] but for judgment forms.
|
|||
|
||||
This function sets @racket[dc-for-text-size]. See also
|
||||
@racket[relation->pict].
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@defform[(relation->pict relation-name)]{
|
||||
This produces a pict, but without setting @racket[dc-for-text-size].
|
||||
It is suitable for use in Slideshow or other libraries that combine
|
||||
|
@ -2508,7 +2508,7 @@ metafunction. It defaults to slideshow's @racket[text] function.
|
|||
}
|
||||
|
||||
@defproc[(arrow->pict [arrow symbol?]) pict?]{
|
||||
Returns the pict corresponding to @racket[arrow].
|
||||
Returns the pict corresponding to @racket[arrow].
|
||||
}
|
||||
|
||||
@defproc[(set-arrow-pict! [arrow symbol?] [proc (-> pict?)]) void?]{
|
||||
|
@ -2660,8 +2660,8 @@ explanation of logical-space):
|
|||
|
||||
@defform[(with-compound-rewriters ([name-symbol proc] ...)
|
||||
expression)]{
|
||||
Shorthand for nested @racket[with-compound-rewriter] expressions.}
|
||||
|
||||
Shorthand for nested @racket[with-compound-rewriter] expressions.}
|
||||
|
||||
@defstruct[lw ([e (or/c string?
|
||||
symbol?
|
||||
pict?
|
||||
|
@ -2695,8 +2695,8 @@ metafunction application. See @racket[to-lw] for the meanings of the other field
|
|||
lw?]{
|
||||
Like @racket[make-lw] but specialized for constructing @racket[lw]s that
|
||||
do not represent unquoted expressions or metafunction applications.
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@defform[(to-lw arg)]{
|
||||
|
||||
This form turns its argument into lw structs that
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
(apply item @index[(map (lambda (x) (format "~a keybinding" x)) keys) key-str] " : " desc)))
|
||||
|
||||
@(define-syntax-rule (def-mod-beg id)
|
||||
(begin
|
||||
(require (for-label racket/base))
|
||||
(define id @racket[#%module-begin])))
|
||||
(begin
|
||||
(require (for-label racket/base))
|
||||
(define id @racket[#%module-begin])))
|
||||
@(def-mod-beg mz-mod-begin)
|
||||
|
||||
@title{Keyboard Shortcuts}
|
||||
|
|
|
@ -36,15 +36,15 @@
|
|||
@racketblock[
|
||||
(class ...
|
||||
...
|
||||
(define status-panel #f)
|
||||
(define/override (make-root-area-container cls parent)
|
||||
(set! status-panel
|
||||
(super make-root-area-container vertical-panel% parent))
|
||||
(let ([root (make-object cls status-panel)])
|
||||
(define status-panel #f)
|
||||
(define/override (make-root-area-container cls parent)
|
||||
(set! status-panel
|
||||
(super make-root-area-container vertical-panel% parent))
|
||||
(let ([root (make-object cls status-panel)])
|
||||
|
||||
(code:comment "... add other children to status-panel ...")
|
||||
(code:comment "... add other children to status-panel ...")
|
||||
|
||||
root))
|
||||
root))
|
||||
...)]
|
||||
|
||||
In this example, status-panel will contain a root panel for the other
|
||||
|
@ -186,7 +186,7 @@
|
|||
See also @racket[frame:setup-size-pref].
|
||||
|
||||
}
|
||||
|
||||
|
||||
@defmethod*[#:mode override (((on-size (width number?) (height number?)) void?))]{
|
||||
|
||||
Updates the preferences, according to the width and
|
||||
|
|
|
@ -85,7 +85,7 @@ that number to control the gauge along the bottom of the splash screen.
|
|||
exact-nonnegative-integer?
|
||||
exact-nonnegative-integer?
|
||||
void?)]{
|
||||
Returns the callback that is invoked when redrawing the splash screen.
|
||||
Returns the callback that is invoked when redrawing the splash screen.
|
||||
}
|
||||
@defproc[(set-splash-paint-callback
|
||||
[cb
|
||||
|
|
|
@ -247,7 +247,7 @@ more specific equivalence comparison.}}
|
|||
@methspec{See @racket[equal<%>].}
|
||||
|
||||
@methimpl{Returns @racket[1].}}
|
||||
|
||||
|
||||
@defmethod[(find-scroll-step [y real?])
|
||||
exact-nonnegative-integer?]{
|
||||
|
||||
|
|
|
@ -9,11 +9,11 @@
|
|||
(except-in wxme/cache-image reader)))
|
||||
|
||||
@(define-syntax-rule (in mod . content)
|
||||
(begin
|
||||
(define-syntax-rule (intro)
|
||||
(begin (require (for-label mod))
|
||||
. content))
|
||||
(intro)))
|
||||
(begin
|
||||
(define-syntax-rule (intro)
|
||||
(begin (require (for-label mod))
|
||||
. content))
|
||||
(intro)))
|
||||
|
||||
@title{WXME Decoding}
|
||||
|
||||
|
|
|
@ -94,8 +94,8 @@ apply a function like @racket[+] to all of the items in the list:
|
|||
|
||||
@def+int[
|
||||
(define (avg lst) (code:comment @#,elem{doesn't always work...})
|
||||
(/ (+ (list-ref lst 0) (list-ref lst 1) (list-ref lst 2))
|
||||
(length lst)))
|
||||
(/ (+ (list-ref lst 0) (list-ref lst 1) (list-ref lst 2))
|
||||
(length lst)))
|
||||
(avg '(1 2 3))
|
||||
(avg '(1 2))
|
||||
]
|
||||
|
|
|
@ -28,9 +28,9 @@ tail position with respect to the @racket[begin] form.
|
|||
(if (zero? height)
|
||||
(void)
|
||||
(begin
|
||||
(display (make-string height #\*))
|
||||
(newline)
|
||||
(print-triangle (sub1 height)))))
|
||||
(display (make-string height #\*))
|
||||
(newline)
|
||||
(print-triangle (sub1 height)))))
|
||||
(print-triangle 4)
|
||||
]
|
||||
|
||||
|
@ -55,10 +55,10 @@ positions, instead of forming an expression, the content of
|
|||
|
||||
@defexamples[
|
||||
(let ([curly 0])
|
||||
(begin
|
||||
(define moe (+ 1 curly))
|
||||
(define larry (+ 1 moe)))
|
||||
(list larry curly moe))
|
||||
(begin
|
||||
(define moe (+ 1 curly))
|
||||
(define larry (+ 1 moe)))
|
||||
(list larry curly moe))
|
||||
]
|
||||
|
||||
This splicing behavior is mainly useful for macros, as we discuss
|
||||
|
@ -114,13 +114,13 @@ result is @racket[#f].
|
|||
|
||||
@defexamples[
|
||||
(define (enumerate lst)
|
||||
(if (null? (cdr lst))
|
||||
(printf "~a.\n" (car lst))
|
||||
(begin
|
||||
(printf "~a, " (car lst))
|
||||
(when (null? (cdr (cdr lst)))
|
||||
(printf "and "))
|
||||
(enumerate (cdr lst)))))
|
||||
(if (null? (cdr lst))
|
||||
(printf "~a.\n" (car lst))
|
||||
(begin
|
||||
(printf "~a, " (car lst))
|
||||
(when (null? (cdr (cdr lst)))
|
||||
(printf "and "))
|
||||
(enumerate (cdr lst)))))
|
||||
(enumerate '("Larry" "Curly" "Moe"))
|
||||
]
|
||||
|
||||
|
|
|
@ -742,8 +742,8 @@ applied first. Then the method-implementing mixins can use
|
|||
(class % ....
|
||||
(define/public (get-color) (void))))
|
||||
(lambda (get-color get-price %) ....
|
||||
(class % ....
|
||||
(define/override (get-color) 'black))))
|
||||
(class % ....
|
||||
(define/override (get-color) 'black))))
|
||||
(list (local-member-name-key get-price)
|
||||
(lambda (get-price get-color %) ....
|
||||
(class % ....
|
||||
|
@ -752,7 +752,7 @@ applied first. Then the method-implementing mixins can use
|
|||
(class % ....
|
||||
(inherit get-color)
|
||||
(define/override (get-price)
|
||||
.... (get-color) ....))))))
|
||||
.... (get-color) ....))))))
|
||||
]
|
||||
|
||||
With this trait encoding, @racket[trait-alias] adds a new method with
|
||||
|
@ -789,11 +789,11 @@ Using this form in conjunction with trait operators such as
|
|||
(define/public (get-color) 'red)))
|
||||
|
||||
(define spots+stripes-trait
|
||||
(trait-sum
|
||||
(trait-exclude (trait-alias spots-trait
|
||||
(trait-sum
|
||||
(trait-exclude (trait-alias spots-trait
|
||||
get-color get-spots-color)
|
||||
get-color)
|
||||
(trait-exclude (trait-alias stripes-trait
|
||||
get-color)
|
||||
(trait-exclude (trait-alias stripes-trait
|
||||
get-color get-stripes-color)
|
||||
get-color)
|
||||
(trait
|
||||
|
|
|
@ -60,9 +60,9 @@ racket
|
|||
[argmax
|
||||
(->i ([f (-> any/c real?)] [lov (and/c pair? list?)]) ()
|
||||
(r (f lov)
|
||||
(lambda (r)
|
||||
(define f@r (f r))
|
||||
(for/and ((v lov)) (>= f@r (f v))))))])
|
||||
(lambda (r)
|
||||
(define f@r (f r))
|
||||
(for/and ([v lov]) (>= f@r (f v))))))])
|
||||
]
|
||||
It is a @emph{dependent} contract that names the two arguments and uses
|
||||
the names to impose a predicate on the result. This predicate computes
|
||||
|
@ -84,9 +84,8 @@ racket
|
|||
(r (f lov)
|
||||
(lambda (r)
|
||||
(define f@r (f r))
|
||||
(and
|
||||
(memq r lov)
|
||||
(for/and ((v lov)) (>= f@r (f v)))))))])
|
||||
(and (memq r lov)
|
||||
(for/and ([v lov]) (>= f@r (f v)))))))])
|
||||
]
|
||||
The @racket[memq] function ensures that @racket[r] is @emph{intensionally equal}
|
||||
@margin-note*{That is, "pointer equality" for those who prefer to think at
|
||||
|
@ -113,14 +112,14 @@ racket
|
|||
(r (f lov)
|
||||
(lambda (r)
|
||||
(define f@r (f r))
|
||||
(and (for/and ((v lov)) (>= f@r (f v)))
|
||||
(and (for/and ([v lov]) (>= f@r (f v)))
|
||||
(eq? (first (memf (lambda (v) (= (f v) f@r)) lov))
|
||||
r)))))])
|
||||
]
|
||||
That is, the @racket[memf] function determines the first element of
|
||||
@racket[lov] whose value under @racket[f] is equal to @racket[r]'s value
|
||||
under @racket[f]. If this element is intensionally equal to @racket[r],
|
||||
the result of @racket[argmax] is correct.
|
||||
the result of @racket[argmax] is correct.
|
||||
|
||||
This second refinement step introduces two problems. First, both conditions
|
||||
recompute the values of @racket[f] for all elements of @racket[lov]. Second,
|
||||
|
@ -157,7 +156,7 @@ racket
|
|||
|
||||
@code:comment{@#,dominates1}
|
||||
(define (dominates-all f@r f lov)
|
||||
(for/and ((v lov)) (>= (f v) f@r)))
|
||||
(for/and ([v lov]) (>= (f v) f@r)))
|
||||
|
||||
@code:comment{@#,first?1}
|
||||
(define (is-first-max? r f@r f lov)
|
||||
|
@ -199,7 +198,7 @@ racket
|
|||
|
||||
@code:comment{@#,dominates2}
|
||||
(define (dominates-all f@r flov)
|
||||
(for/and ((f@v flov)) (>= f@r f@v)))
|
||||
(for/and ([f@v flov]) (>= f@r f@v)))
|
||||
|
||||
@code:comment{@#,first?2}
|
||||
(define (is-first-max? r f@r lov+flov)
|
||||
|
|
|
@ -225,7 +225,7 @@ of numbers or a string into a new string:
|
|||
The contract for such a function is formed with the @racket[case->]
|
||||
combinator, which combines as many functional contracts as needed:
|
||||
@racketblock[
|
||||
(provide/contract
|
||||
(provide/contract
|
||||
[report-cost
|
||||
(case->
|
||||
(integer? integer? . -> . string?)
|
||||
|
|
|
@ -81,26 +81,24 @@ streams like this:
|
|||
@interaction[
|
||||
#:eval e
|
||||
(define stream/c
|
||||
(promise/c
|
||||
(or/c
|
||||
null?
|
||||
(cons/c number? stream/c))))
|
||||
(promise/c
|
||||
(or/c null?
|
||||
(cons/c number? stream/c))))
|
||||
]
|
||||
@close-eval[e]
|
||||
|
||||
|
||||
Unfortunately, this does not work because the value of
|
||||
@racket[stream/c] is needed before it is defined. Put another way, all
|
||||
of the combinators evaluate their arguments eagerly, even thought the
|
||||
values that they accept do not.
|
||||
|
||||
Instead, use
|
||||
Instead, use
|
||||
@racketblock[
|
||||
(define stream/c
|
||||
(promise/c
|
||||
(or/c
|
||||
null?
|
||||
(cons/c 1
|
||||
(recursive-contract stream/c)))))
|
||||
(promise/c
|
||||
(or/c
|
||||
null?
|
||||
(cons/c 1 (recursive-contract stream/c)))))
|
||||
]
|
||||
|
||||
The use of @racket[recursive-contract] delays the evaluation of the
|
||||
|
|
|
@ -93,16 +93,16 @@ provide/contract'd. This is currently buggy so this
|
|||
discussion is elided. Here's the expansion of
|
||||
the requiring module, just to give an idea:
|
||||
|
||||
(module m racket
|
||||
(module m racket
|
||||
(require mzlib/contract)
|
||||
(provide/contract [x x-ctc]))
|
||||
(provide/contract [x x-ctc]))
|
||||
|
||||
(module n racket (require m) (define (f) ... x ...))
|
||||
==>
|
||||
(module n racket
|
||||
(require (rename m x x-real))
|
||||
(define x (apply-contract x-real x-ctc ...))
|
||||
(define (f) ... x ...))
|
||||
(module n racket
|
||||
(require (rename m x x-real))
|
||||
(define x (apply-contract x-real x-ctc ...))
|
||||
(define (f) ... x ...))
|
||||
|
||||
The intention is to only do the work of applying the
|
||||
contract once (per variable reference to a
|
||||
|
|
|
@ -261,7 +261,7 @@ resulting iteration can be performed more efficiently than plain
|
|||
@racket[for/vector] or @racket[for*/vector]:
|
||||
|
||||
@interaction[
|
||||
(let ((chapters '("Intro" "Details" "Conclusion")))
|
||||
(let ([chapters '("Intro" "Details" "Conclusion")])
|
||||
(for/vector #:length (length chapters) ([i (in-naturals 1)]
|
||||
[chapter chapters])
|
||||
(string-append (number->string i) ". " chapter)))
|
||||
|
|
|
@ -64,18 +64,18 @@ Consider the following core of a Mandelbrot-set computation:
|
|||
|
||||
@racketblock[
|
||||
(define (mandelbrot iterations x y n)
|
||||
(let ((ci (- (/ (* 2.0 y) n) 1.0))
|
||||
(cr (- (/ (* 2.0 x) n) 1.5)))
|
||||
(let loop ((i 0) (zr 0.0) (zi 0.0))
|
||||
(let ([ci (- (/ (* 2.0 y) n) 1.0)]
|
||||
[cr (- (/ (* 2.0 x) n) 1.5)])
|
||||
(let loop ([i 0] [zr 0.0] [zi 0.0])
|
||||
(if (> i iterations)
|
||||
i
|
||||
(let ((zrq (* zr zr))
|
||||
(ziq (* zi zi)))
|
||||
(let ([zrq (* zr zr)]
|
||||
[ziq (* zi zi)])
|
||||
(cond
|
||||
((> (+ zrq ziq) 4.0) i)
|
||||
(else (loop (add1 i)
|
||||
(+ (- zrq ziq) cr)
|
||||
(+ (* 2.0 zr zi) ci)))))))))
|
||||
[(> (+ zrq ziq) 4.0) i]
|
||||
[else (loop (add1 i)
|
||||
(+ (- zrq ziq) cr)
|
||||
(+ (* 2.0 zr zi) ci))]))))))
|
||||
]
|
||||
|
||||
The expressions @racket[(mandelbrot 10000000 62 500 1000)] and
|
||||
|
@ -110,8 +110,8 @@ first the problem:
|
|||
|
||||
@racketblock[
|
||||
(define (mandelbrot iterations x y n)
|
||||
(let ((ci (- (/ (* 2.0 (->fl y)) (->fl n)) 1.0))
|
||||
(cr (- (/ (* 2.0 (->fl x)) (->fl n)) 1.5)))
|
||||
(let ([ci (- (/ (* 2.0 (->fl y)) (->fl n)) 1.0)]
|
||||
[cr (- (/ (* 2.0 (->fl x)) (->fl n)) 1.5)])
|
||||
....))
|
||||
]
|
||||
|
||||
|
@ -128,18 +128,18 @@ much less allocation:
|
|||
|
||||
@racketblock[
|
||||
(define (mandelbrot iterations x y n)
|
||||
(let ((ci (fl- (fl/ (* 2.0 (->fl y)) (->fl n)) 1.0))
|
||||
(cr (fl- (fl/ (* 2.0 (->fl x)) (->fl n)) 1.5)))
|
||||
(let loop ((i 0) (zr 0.0) (zi 0.0))
|
||||
(let ([ci (fl- (fl/ (* 2.0 (->fl y)) (->fl n)) 1.0)]
|
||||
[cr (fl- (fl/ (* 2.0 (->fl x)) (->fl n)) 1.5)])
|
||||
(let loop ([i 0] [zr 0.0] [zi 0.0])
|
||||
(if (> i iterations)
|
||||
i
|
||||
(let ((zrq (fl* zr zr))
|
||||
(ziq (fl* zi zi)))
|
||||
(let ([zrq (fl* zr zr)]
|
||||
[ziq (fl* zi zi)])
|
||||
(cond
|
||||
((fl> (fl+ zrq ziq) 4.0) i)
|
||||
(else (loop (add1 i)
|
||||
(fl+ (fl- zrq ziq) cr)
|
||||
(fl+ (fl* 2.0 (fl* zr zi)) ci)))))))))
|
||||
[(fl> (fl+ zrq ziq) 4.0) i]
|
||||
[else (loop (add1 i)
|
||||
(fl+ (fl- zrq ziq) cr)
|
||||
(fl+ (fl* 2.0 (fl* zr zi)) ci))]))))))
|
||||
]
|
||||
|
||||
This conversion can speed @racket[mandelbrot] by a factor of 8, even
|
||||
|
|
|
@ -315,8 +315,8 @@ the source form are identifiers. We could use a
|
|||
(syntax-case stx ()
|
||||
[(rotate a c ...)
|
||||
(begin
|
||||
(check-ids stx #'(a c ...))
|
||||
#'(shift-to (c ... a) (a c ...)))]))
|
||||
(check-ids stx #'(a c ...))
|
||||
#'(shift-to (c ... a) (a c ...)))]))
|
||||
]
|
||||
|
||||
The @racket[check-ids] function can use the @racket[syntax->list]
|
||||
|
|
|
@ -217,13 +217,13 @@ racket
|
|||
(+ n 17))
|
||||
|
||||
(define-syntax (def-go stx)
|
||||
(syntax-case stx ()
|
||||
[(_ go)
|
||||
(protect-syntax
|
||||
#'(define-syntax (go stx)
|
||||
(syntax-case stx ()
|
||||
[(_ x)
|
||||
(protect-syntax #'(unchecked-go 8 x))])))]))
|
||||
(syntax-case stx ()
|
||||
[(_ go)
|
||||
(protect-syntax
|
||||
#'(define-syntax (go stx)
|
||||
(syntax-case stx ()
|
||||
[(_ x)
|
||||
(protect-syntax #'(unchecked-go 8 x))])))]))
|
||||
]
|
||||
|
||||
When @racket[def-go] is used inside another module to defined
|
||||
|
@ -247,13 +247,13 @@ racket
|
|||
(lambda (stx) (syntax-arm stx insp))))
|
||||
|
||||
(define-syntax (def-go stx)
|
||||
(syntax-case stx ()
|
||||
[(_ go)
|
||||
(protect-syntax
|
||||
#'(define-syntax (go stx)
|
||||
(syntax-case stx ()
|
||||
[(_ x)
|
||||
(go-syntax-protect #'(unchecked-go 8 x))])))]))
|
||||
(syntax-case stx ()
|
||||
[(_ go)
|
||||
(protect-syntax
|
||||
#'(define-syntax (go stx)
|
||||
(syntax-case stx ()
|
||||
[(_ x)
|
||||
(go-syntax-protect #'(unchecked-go 8 x))])))]))
|
||||
]
|
||||
|
||||
@;------------------------------------------------------------------------
|
||||
|
|
|
@ -313,28 +313,28 @@ racket
|
|||
|
||||
(define toy-store@-maker
|
||||
(lambda (the-color)
|
||||
(unit
|
||||
(import toy-factory^)
|
||||
(export toy-store^)
|
||||
(unit
|
||||
(import toy-factory^)
|
||||
(export toy-store^)
|
||||
|
||||
(define inventory null)
|
||||
(define inventory null)
|
||||
|
||||
(define (store-color) the-color)
|
||||
(define (store-color) the-color)
|
||||
|
||||
(code:comment @#,t{the rest is the same as before})
|
||||
(code:comment @#,t{the rest is the same as before})
|
||||
|
||||
(define (maybe-repaint t)
|
||||
(if (eq? (toy-color t) (store-color))
|
||||
t
|
||||
(repaint t (store-color))))
|
||||
(define (maybe-repaint t)
|
||||
(if (eq? (toy-color t) (store-color))
|
||||
t
|
||||
(repaint t (store-color))))
|
||||
|
||||
(define (stock! n)
|
||||
(set! inventory
|
||||
(append inventory
|
||||
(map maybe-repaint
|
||||
(build-toys n)))))
|
||||
(define (stock! n)
|
||||
(set! inventory
|
||||
(append inventory
|
||||
(map maybe-repaint
|
||||
(build-toys n)))))
|
||||
|
||||
(define (get-inventory) inventory))))
|
||||
(define (get-inventory) inventory))))
|
||||
|
||||
(provide toy-store@-maker)
|
||||
]
|
||||
|
|
|
@ -122,7 +122,7 @@ the function.}
|
|||
|
||||
|
||||
@defform[(define-datatype dataype-name [variant-name field-name ...] ...)]{
|
||||
|
||||
|
||||
A short-hand for defining a group of related structures. The following @racket[define-datatype]:
|
||||
|
||||
@racketblock[
|
||||
|
@ -237,7 +237,7 @@ of the initial @racket[expression].}
|
|||
|
||||
|
||||
@defform[(match expression [pattern expression] ...)]{
|
||||
|
||||
|
||||
A @racket[match] form contains one or more clauses that are surrounded by
|
||||
square brackets. Each clause contains a pattern---a description of a value---and
|
||||
an answer @racket[expression]. The initial @racket[expression] is evaluated,
|
||||
|
|
|
@ -433,7 +433,7 @@ A unit that imports nothing and exports @racket[compiler:embed^].}
|
|||
@defproc[(find-exe [gracket? boolean?]
|
||||
[variant (or/c 'cgc '3m) (system-type 'gc)])
|
||||
path?]{
|
||||
|
||||
Finds the path to the racket (or gracket) executable.
|
||||
|
||||
Finds the path to the racket (or gracket) executable.
|
||||
}
|
||||
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
(only-in setup/infotab require)))
|
||||
|
||||
@(begin
|
||||
(define-syntax-rule (define-racket-require id)
|
||||
(begin
|
||||
(require (for-label (only-in racket require)))
|
||||
(define id @racket[require])))
|
||||
(define-racket-require racket:require))
|
||||
(define-syntax-rule (define-racket-require id)
|
||||
(begin
|
||||
(require (for-label (only-in racket require)))
|
||||
(define id @racket[require])))
|
||||
(define-racket-require racket:require))
|
||||
|
||||
@title[#:tag "info.rkt"]{@filepath{info.rkt} File Format}
|
||||
|
||||
|
|
|
@ -384,8 +384,8 @@ result will not call @racket[proc] with @racket['unlock].)
|
|||
(when ok-to-compile?
|
||||
(printf "Do compile here ...\n")))
|
||||
(lambda ()
|
||||
(when locked?
|
||||
(lc 'unlock zo-name)))))
|
||||
(when locked?
|
||||
(lc 'unlock zo-name)))))
|
||||
]
|
||||
}
|
||||
|
||||
|
|
|
@ -27,12 +27,12 @@
|
|||
racket/future))
|
||||
|
||||
@(define-syntax-rule (local-module mod . body)
|
||||
(begin
|
||||
(define-syntax-rule (go)
|
||||
(begin
|
||||
(require (for-label mod))
|
||||
. body))
|
||||
(go)))
|
||||
(begin
|
||||
(define-syntax-rule (go)
|
||||
(begin
|
||||
(require (for-label mod))
|
||||
. body))
|
||||
(go)))
|
||||
|
||||
@(define ref-src
|
||||
'(lib "scribblings/reference/reference.scrbl"))
|
||||
|
|
|
@ -280,7 +280,8 @@ For communication among @tech{places}, the new byte string is allocated in the
|
|||
the other operations.
|
||||
@examples[
|
||||
(define b
|
||||
(bytes->string/utf-8 (bytes #xc3 #xa7 #xc3 #xb0 #xc3 #xb6 #xc2 #xa3)))
|
||||
(bytes->string/utf-8
|
||||
(bytes #xc3 #xa7 #xc3 #xb0 #xc3 #xb6 #xc2 #xa3)))
|
||||
|
||||
(string->bytes/utf-8 b)
|
||||
(bytes->string/utf-8 (string->bytes/utf-8 b))
|
||||
|
@ -316,7 +317,7 @@ For communication among @tech{places}, the new byte string is allocated in the
|
|||
|
||||
@examples[
|
||||
(define b
|
||||
(bytes->string/latin-1 (bytes #xfe #xd3 #xd1 #xa5)))
|
||||
(bytes->string/latin-1 (bytes #xfe #xd3 #xd1 #xa5)))
|
||||
|
||||
(string->bytes/latin-1 b)
|
||||
(bytes->string/latin-1 (string->bytes/latin-1 b))
|
||||
|
|
|
@ -12,15 +12,15 @@
|
|||
[(_ s ... s0) (elem (elem ", " (secref s)) ... ", and " (secref s0))]))
|
||||
|
||||
(define-syntax (defclassforms stx)
|
||||
(syntax-case stx (*)
|
||||
[(_ [* (form ...) (also ...)])
|
||||
#'(defform* (form ...)
|
||||
"See " @racket[class*] (sees also ...) "; use"
|
||||
" outside the body of a " @racket[class*] " form is a syntax error.")]
|
||||
[(_ [form (also ...)])
|
||||
#'(defclassforms [* (form) (also ...)])]
|
||||
[(_ form ...)
|
||||
#'(begin (defclassforms form) ...)]))
|
||||
(syntax-case stx (*)
|
||||
[(_ [* (form ...) (also ...)])
|
||||
#'(defform* (form ...)
|
||||
"See " @racket[class*] (sees also ...) "; use"
|
||||
" outside the body of a " @racket[class*] " form is a syntax error.")]
|
||||
[(_ [form (also ...)])
|
||||
#'(defclassforms [* (form) (also ...)])]
|
||||
[(_ form ...)
|
||||
#'(begin (defclassforms form) ...)]))
|
||||
|
||||
(define-syntax (defstarshorthands stx)
|
||||
(syntax-case stx ()
|
||||
|
@ -292,13 +292,13 @@ interface @racket[(class->interface object%)], and is transparent
|
|||
(lambda kw-formals expr ...+)
|
||||
(case-lambda (formals expr ...+) ...)
|
||||
(#%plain-lambda formals expr ...+)
|
||||
(let-values (((id) method-procedure) ...)
|
||||
(let-values ([(id) method-procedure] ...)
|
||||
method-procedure)
|
||||
(letrec-values (((id) method-procedure) ...)
|
||||
(letrec-values ([(id) method-procedure] ...)
|
||||
method-procedure)
|
||||
(let-values (((id) method-procedure) ...+)
|
||||
(let-values ([(id) method-procedure] ...+)
|
||||
id)
|
||||
(letrec-values (((id) method-procedure) ...+)
|
||||
(letrec-values ([(id) method-procedure] ...+)
|
||||
id)])]{
|
||||
|
||||
Produces a class value.
|
||||
|
@ -1366,11 +1366,11 @@ Produces a @tech{trait} that combines all of the methods of the given
|
|||
|
||||
@racketblock[
|
||||
(define t1
|
||||
(trait
|
||||
(define/public (m1) 1)))
|
||||
(trait
|
||||
(define/public (m1) 1)))
|
||||
(define t2
|
||||
(trait
|
||||
(define/public (m2) 2)))
|
||||
(trait
|
||||
(define/public (m2) 2)))
|
||||
(define t3 (trait-sum t1 t2))
|
||||
]
|
||||
|
||||
|
@ -1378,8 +1378,8 @@ creates a trait @racket[t3] that is equivalent to
|
|||
|
||||
@racketblock[
|
||||
(trait
|
||||
(define/public (m1) 1)
|
||||
(define/public (m2) 2))
|
||||
(define/public (m1) 1)
|
||||
(define/public (m2) 2))
|
||||
]
|
||||
|
||||
but @racket[t1] and @racket[t2] can still be used individually or
|
||||
|
@ -1649,12 +1649,12 @@ Also, method contracts for @racket[object/c] follow those for
|
|||
behaves as if its class had been wrapped with the equivalent
|
||||
@racket[class/c] contract.
|
||||
}
|
||||
|
||||
|
||||
@defproc[(instanceof/c [class-contract contract?]) contract?]{
|
||||
Produces a contract for an object, where the object is an
|
||||
instance of a class that conforms to @racket[class-contract].
|
||||
}
|
||||
|
||||
|
||||
@defform/subs[
|
||||
#:literals (field -> ->* ->d)
|
||||
|
||||
|
|
|
@ -172,18 +172,18 @@ default error display handler (see
|
|||
@secref["errorproc"]).}
|
||||
|
||||
@examples[
|
||||
(define (extract-current-continuation-marks key)
|
||||
(continuation-mark-set->list
|
||||
(current-continuation-marks)
|
||||
key))
|
||||
(define (extract-current-continuation-marks key)
|
||||
(continuation-mark-set->list
|
||||
(current-continuation-marks)
|
||||
key))
|
||||
|
||||
(with-continuation-mark 'key 'mark
|
||||
(with-continuation-mark 'key 'mark
|
||||
(extract-current-continuation-marks 'key))
|
||||
|
||||
(with-continuation-mark 'key1 'mark1
|
||||
(with-continuation-mark 'key2 'mark2
|
||||
(list
|
||||
(extract-current-continuation-marks 'key1)
|
||||
(with-continuation-mark 'key1 'mark1
|
||||
(with-continuation-mark 'key2 'mark2
|
||||
(list
|
||||
(extract-current-continuation-marks 'key1)
|
||||
(extract-current-continuation-marks 'key2))))
|
||||
|
||||
(with-continuation-mark 'key 'mark1
|
||||
|
|
|
@ -997,7 +997,7 @@ is bound to vectors of two elements, the exported identifier and a
|
|||
syntax object for the expression that produces the contract controlling
|
||||
the export.
|
||||
}
|
||||
|
||||
|
||||
@subsection{Nested Contract Boundaries}
|
||||
@defmodule*/no-declare[(racket/contract/region)]
|
||||
@declare-exporting-ctc[racket/contract/region]
|
||||
|
@ -1091,7 +1091,7 @@ The @racket[define-struct/contract] form only allows a subset of the
|
|||
|
||||
@subsection{Low-level Contract Boundaries}
|
||||
@declare-exporting-ctc[racket/contract/base]
|
||||
|
||||
|
||||
@defform*[[(contract contract-expr to-protect-expr
|
||||
positive-blame-expr negative-blame-expr)
|
||||
(contract contract-expr to-protect-expr
|
||||
|
@ -1808,7 +1808,7 @@ are below):
|
|||
@; ------------------------------------------------------------------------
|
||||
|
||||
@subsection{Utilities for Building New Combinators}
|
||||
|
||||
|
||||
@defproc[(contract-stronger? [x contract?] [y contract?]) boolean?]{
|
||||
Returns @racket[#t] if the contract @racket[x] accepts either fewer
|
||||
or the same number of values as @racket[y] does.
|
||||
|
@ -1845,7 +1845,7 @@ contract holds.}
|
|||
Produces the first-order test used by @racket[or/c] to match values to
|
||||
higher-order contracts.
|
||||
}
|
||||
|
||||
|
||||
@section{Contract Utilities}
|
||||
|
||||
@declare-exporting-ctc[racket/contract/base]
|
||||
|
|
|
@ -9,27 +9,27 @@
|
|||
|
||||
;; hacky?
|
||||
(define file-eval
|
||||
(lambda ()
|
||||
(let ([the-eval (make-base-eval)])
|
||||
(the-eval '(require (for-syntax racket/base)
|
||||
racket/file))
|
||||
(the-eval '(define some-file (make-temporary-file)))
|
||||
(the-eval '(define some-other-file (make-temporary-file)))
|
||||
the-eval)))
|
||||
(lambda ()
|
||||
(let ([the-eval (make-base-eval)])
|
||||
(the-eval '(require (for-syntax racket/base)
|
||||
racket/file))
|
||||
(the-eval '(define some-file (make-temporary-file)))
|
||||
(the-eval '(define some-other-file (make-temporary-file)))
|
||||
the-eval)))
|
||||
|
||||
(define-syntax file-examples
|
||||
(syntax-rules ()
|
||||
[(_ expr ...)
|
||||
(let [(my-eval (file-eval))]
|
||||
(define (clean)
|
||||
(my-eval '(for [(i (list some-file some-other-file))]
|
||||
(when (file-exists? i)
|
||||
(delete-file i)))))
|
||||
(clean)
|
||||
(begin0
|
||||
(defexamples #:eval my-eval
|
||||
expr ...)
|
||||
(clean)))]))
|
||||
(define (clean)
|
||||
(my-eval '(for [(i (list some-file some-other-file))]
|
||||
(when (file-exists? i)
|
||||
(delete-file i)))))
|
||||
(clean)
|
||||
(begin0
|
||||
(defexamples #:eval my-eval
|
||||
expr ...)
|
||||
(clean)))]))
|
||||
|
||||
"")
|
||||
|
||||
|
|
|
@ -196,4 +196,3 @@ For communication among @tech{places}, the new @tech{fxvector} is
|
|||
allocated in the @tech{shared memory space}.
|
||||
|
||||
@mz-examples[#:eval flfx-eval (make-shared-fxvector 4 3)]}
|
||||
|
||||
|
|
|
@ -180,7 +180,7 @@ Maps @racket[key] to @racket[v] in @racket[hash], overwriting
|
|||
any existing mapping for @racket[key].
|
||||
|
||||
@see-also-caveats[]}
|
||||
|
||||
|
||||
@defproc[(hash-set*! [hash (and/c hash? (not/c immutable?))]
|
||||
[key any/c]
|
||||
[v any/c]
|
||||
|
@ -204,7 +204,7 @@ Functionally extends @racket[hash] by mapping @racket[key] to
|
|||
returning the extended hash table.
|
||||
|
||||
@see-also-mutable-key-caveat[]}
|
||||
|
||||
|
||||
@defproc[(hash-set* [hash (and/c hash? immutable?)]
|
||||
[key any/c]
|
||||
[v any/c]
|
||||
|
@ -329,25 +329,25 @@ otherwise the traversal skips a deleted key or uses the remapped key's
|
|||
new value.
|
||||
|
||||
@see-also-concurrency-caveat[]}
|
||||
|
||||
|
||||
@defproc[(hash-keys [hash hash?])
|
||||
(listof any/c)]{
|
||||
Returns a list of the keys of @racket[hash] in an unspecified order.
|
||||
|
||||
|
||||
See @racket[hash-map] for information about modifying @racket[hash]
|
||||
during @racket[hash-keys]. @see-also-concurrency-caveat[]}
|
||||
|
||||
@defproc[(hash-values [hash hash?])
|
||||
(listof any/c)]{
|
||||
Returns a list of the values of @racket[hash] in an unspecified order.
|
||||
|
||||
|
||||
See @racket[hash-map] for information about modifying @racket[hash]
|
||||
during @racket[hash-values]. @see-also-concurrency-caveat[]}
|
||||
|
||||
|
||||
@defproc[(hash->list [hash hash?])
|
||||
(listof (cons/c any/c any/c))]{
|
||||
Returns a list of the key--value pairs of @racket[hash] in an unspecified order.
|
||||
|
||||
|
||||
See @racket[hash-map] for information about modifying @racket[hash]
|
||||
during @racket[hash->list]. @see-also-concurrency-caveat[]}
|
||||
|
||||
|
|
|
@ -144,8 +144,8 @@ is equivalent to
|
|||
@racketblock[
|
||||
(let ([l (current-logger)])
|
||||
(when (log-level? l '@#,racket[_level])
|
||||
(log-message l '@#,racket[_level] string-expr
|
||||
(current-continuation-marks))))
|
||||
(log-message l '@#,racket[_level] string-expr
|
||||
(current-continuation-marks))))
|
||||
]}
|
||||
|
||||
@; ----------------------------------------
|
||||
|
|
|
@ -480,9 +480,10 @@ instead of @racket[match].}
|
|||
A @racket[match] pattern form that matches an instance of a structure
|
||||
type named @racket[struct-id], where the field @racket[field] in the
|
||||
instance matches the corresponding @racket[pat].
|
||||
|
||||
Any field of @racket[struct-id] may be omitted, and such fields can occur in any order.
|
||||
|
||||
|
||||
Any field of @racket[struct-id] may be omitted, and such fields can
|
||||
occur in any order.
|
||||
|
||||
@defexamples[
|
||||
#:eval match-eval
|
||||
(define-struct tree (val left right))
|
||||
|
|
|
@ -49,14 +49,14 @@ the grammar for @racket[_module-path] for @racket[require],
|
|||
@racket[#f] otherwise.}
|
||||
|
||||
|
||||
@defparam[current-module-name-resolver proc
|
||||
@defparam[current-module-name-resolver proc
|
||||
(case->
|
||||
(resolved-module-path? . -> . any)
|
||||
((or/c module-path? path?)
|
||||
(or/c #f resolved-module-path?)
|
||||
(or/c #f syntax?)
|
||||
(or/c #f resolved-module-path?)
|
||||
(or/c #f syntax?)
|
||||
boolean?
|
||||
. -> .
|
||||
. -> .
|
||||
resolved-module-path?))]{
|
||||
|
||||
A parameter that determines the current @deftech{module name
|
||||
|
|
|
@ -44,7 +44,7 @@ new parameter value. A guard procedure can raise an exception to
|
|||
reject a change to the parameter's value. The @racket[guard] is not
|
||||
applied to the initial @racket[v].}
|
||||
|
||||
@defform[(parameterize ((parameter-expr value-expr) ...)
|
||||
@defform[(parameterize ([parameter-expr value-expr] ...)
|
||||
body ...+)
|
||||
#:contracts
|
||||
([parameter-expr parameter?])]{
|
||||
|
|
|
@ -739,8 +739,8 @@ values from the generator.
|
|||
(if (null? x)
|
||||
0
|
||||
(begin
|
||||
(yield (car x))
|
||||
(loop (cdr x)))))))
|
||||
(yield (car x))
|
||||
(loop (cdr x)))))))
|
||||
(g)
|
||||
(g)
|
||||
(g)
|
||||
|
@ -812,8 +812,8 @@ Produces a @tech{sequence} that encapsulates the @tech{generator} formed by
|
|||
(if (null? x)
|
||||
my-stop-value
|
||||
(begin
|
||||
(yield (car x))
|
||||
(loop (cdr x)))))))
|
||||
(yield (car x))
|
||||
(loop (cdr x)))))))
|
||||
|
||||
(for/list ([i (in-producer my-generator my-stop-value)])
|
||||
i)]}
|
||||
|
|
|
@ -209,7 +209,7 @@ Returns @racket[#t] if @racket[st] compares elements with @racket[eq?],
|
|||
|
||||
@defproc[(set/c [contract chaperone-contract?] [#:cmp cmp (or/c 'dont-care 'equal 'eqv 'eq) 'dont-care]) contract?]{
|
||||
Constructs a contract that recognizes sets whose elements match @racket[contract].
|
||||
|
||||
|
||||
If @racket[cmp] is @racket['dont-care], then the equality notion of the set is not considered
|
||||
when checking the contract. Otherwise, the contract accepts only sets with the corresponding
|
||||
notion of equality.
|
||||
|
|
|
@ -24,7 +24,7 @@ used as a macro that expands to a use of the target identifier, but
|
|||
@racket[syntax-local-value] of @racket[id] does not produce
|
||||
the target's value.}
|
||||
|
||||
@defform[(syntax-parameterize ((id expr) ...) body-expr ...+)]{
|
||||
@defform[(syntax-parameterize ([id expr] ...) body-expr ...+)]{
|
||||
|
||||
@margin-note/ref{See also @racket[splicing-syntax-parameterize].}
|
||||
|
||||
|
|
|
@ -139,7 +139,7 @@ For example, the expression
|
|||
expands to
|
||||
|
||||
@racketblock[
|
||||
(let ((or-part x)) (if or-part or-part (or y)))
|
||||
(let ([or-part x]) (if or-part or-part (or y)))
|
||||
]
|
||||
|
||||
which, in turn, expands to
|
||||
|
|
|
@ -210,9 +210,9 @@ the binding (according to @racket[free-identifier=?]) matters.}
|
|||
(if expr expr expr)
|
||||
(begin expr ...+)
|
||||
(begin0 expr expr ...)
|
||||
(let-values (((id ...) expr) ...)
|
||||
(let-values ([(id ...) expr] ...)
|
||||
expr ...+)
|
||||
(letrec-values (((id ...) expr) ...)
|
||||
(letrec-values ([(id ...) expr] ...)
|
||||
expr ...+)
|
||||
(set! id expr)
|
||||
(@#,racket[quote] datum)
|
||||
|
@ -756,21 +756,21 @@ bucket-2
|
|||
(syntax-rules ()
|
||||
[(def-and-use)
|
||||
(begin
|
||||
(code:comment @#,t{Initial reference to @racket[even] precedes definition:})
|
||||
(define (odd x) (if (zero? x) #f (even (sub1 x))))
|
||||
(define (even x) (if (zero? x) #t (odd (sub1 x))))
|
||||
(odd 17))]))
|
||||
(code:comment @#,t{Initial reference to @racket[even] precedes definition:})
|
||||
(define (odd x) (if (zero? x) #f (even (sub1 x))))
|
||||
(define (even x) (if (zero? x) #t (odd (sub1 x))))
|
||||
(odd 17))]))
|
||||
(defs-and-uses/fail)
|
||||
|
||||
|
||||
(define-syntax defs-and-uses
|
||||
(syntax-rules ()
|
||||
[(def-and-use)
|
||||
(begin
|
||||
(code:comment @#,t{Declare before definition via no-values @racket[define-syntaxes]:})
|
||||
(define-syntaxes (odd even) (values))
|
||||
(define (odd x) (if (zero? x) #f (even (sub1 x))))
|
||||
(define (even x) (if (zero? x) #t (odd (sub1 x))))
|
||||
(odd 17))]))
|
||||
(code:comment @#,t{Declare before definition via no-values @racket[define-syntaxes]:})
|
||||
(define-syntaxes (odd even) (values))
|
||||
(define (odd x) (if (zero? x) #f (even (sub1 x))))
|
||||
(define (even x) (if (zero? x) #t (odd (sub1 x))))
|
||||
(odd 17))]))
|
||||
(defs-and-uses)
|
||||
]
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ is prefixed with the special form name as described under
|
|||
|
||||
@examples[#:eval the-eval
|
||||
(wrong-syntax #'here "expected ~s" 'there)
|
||||
(parameterize ((current-syntax-context #'(look over here)))
|
||||
(parameterize ([current-syntax-context #'(look over here)])
|
||||
(wrong-syntax #'here "expected ~s" 'there))
|
||||
]
|
||||
|
||||
|
@ -117,7 +117,7 @@ A macro using @racket[wrong-syntax] might set the syntax context at the very
|
|||
beginning of its transformation as follows:
|
||||
@RACKETBLOCK[
|
||||
(define-syntax (my-macro stx)
|
||||
(parameterize ((current-syntax-context stx))
|
||||
(parameterize ([current-syntax-context stx])
|
||||
(syntax-case stx ()
|
||||
___)))
|
||||
]
|
||||
|
|
|
@ -905,18 +905,18 @@ follows.
|
|||
chickens))
|
||||
|
||||
(module nest2 racket
|
||||
(define-for-syntax eggs 2)
|
||||
(provide (for-syntax eggs)))
|
||||
(define-for-syntax eggs 2)
|
||||
(provide (for-syntax eggs)))
|
||||
(require (for-meta 2 racket/base)
|
||||
(for-syntax 'nest2))
|
||||
(define-syntax (test stx)
|
||||
(define-syntax (show-eggs stx)
|
||||
(printf "Eggs are ~a\n" eggs)
|
||||
#'0)
|
||||
(begin
|
||||
(show-eggs)
|
||||
#'0))
|
||||
(test)
|
||||
(define-syntax (show-eggs stx)
|
||||
(printf "Eggs are ~a\n" eggs)
|
||||
#'0)
|
||||
(begin
|
||||
(show-eggs)
|
||||
#'0))
|
||||
(test)
|
||||
]}
|
||||
|
||||
@specsubform[#:literals (for-syntax)
|
||||
|
@ -2144,8 +2144,8 @@ be defined by the same @racket[define-for-syntax] form.
|
|||
@defexamples[#:eval (syntax-eval)
|
||||
(define-for-syntax helper 2)
|
||||
(define-syntax (make-two syntax-object)
|
||||
(printf "helper is ~a\n" helper)
|
||||
#'2)
|
||||
(printf "helper is ~a\n" helper)
|
||||
#'2)
|
||||
(make-two)
|
||||
(code:comment @#,t{`helper' is not bound in the runtime phase})
|
||||
helper
|
||||
|
|
|
@ -144,7 +144,7 @@ result is the result of @racket[expr].}
|
|||
@note-lib-only[racket/date]
|
||||
|
||||
@defproc[(current-date) date?]{
|
||||
|
||||
|
||||
An abbreviation for @racket[(seconds->date (current-seconds))].}
|
||||
|
||||
@defproc[(date->string [date date?] [time? any/c #f]) string?]{
|
||||
|
|
|
@ -67,7 +67,7 @@ slot is position @racket[0], and the last slot is one less than
|
|||
void?]{
|
||||
|
||||
Updates the slot @racket[pos] of @racket[vec] to contain @racket[v].}
|
||||
|
||||
|
||||
@defproc[(vector->list [vec vector?]) list?]{
|
||||
|
||||
Returns a list with the same length and elements as @racket[vec].}
|
||||
|
|
|
@ -36,7 +36,7 @@ As an example,
|
|||
|
||||
(: my-sqr (Real -> Real))
|
||||
(define (my-sqr x)
|
||||
(* x x))
|
||||
(* x x))
|
||||
(my-sqr 42)]
|
||||
}|
|
||||
uses an evaluator whose language is @racketmodname[typed/racket/base].
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
@(define-syntax-rule (def base-author)
|
||||
(begin
|
||||
(require (for-label scribble/base))
|
||||
(define base-author @racket[author])))
|
||||
(require (for-label scribble/base))
|
||||
(define base-author @racket[author])))
|
||||
@(def base-author)
|
||||
|
||||
@title{JFP Paper Format}
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
@(define-syntax-rule (def base-author)
|
||||
(begin
|
||||
(require (for-label scribble/base))
|
||||
(define base-author @racket[author])))
|
||||
(require (for-label scribble/base))
|
||||
(define base-author @racket[author])))
|
||||
@(def base-author)
|
||||
|
||||
@title{LNCS Paper Format}
|
||||
|
@ -47,7 +47,7 @@ arguments to @racket[institutes].
|
|||
#:contracts ([pre-content-expr pre-content?])]{
|
||||
|
||||
The @racket[pre-content-expr]s are used as the institutions of the authors.
|
||||
|
||||
|
||||
}
|
||||
|
||||
@defidform[institute]{For use only in @racket[institutes].}
|
||||
|
|
|
@ -477,7 +477,7 @@ and one that combines several modules) via your own
|
|||
@defform/subs[(declare-exporting mod-path ... maybe-sources)
|
||||
([maybe-sources code:blank
|
||||
(code:line #:use-sources (mod-path ...))])]{
|
||||
|
||||
|
||||
Associates the @racket[mod-path]s to all bindings defined within the
|
||||
enclosing section, except as overridden by other
|
||||
@racket[declare-exporting] declarations in nested sub-sections. The
|
||||
|
|
|
@ -16,9 +16,9 @@
|
|||
|
||||
@(begin
|
||||
(define-syntax-rule (def-render-mixin id)
|
||||
(begin
|
||||
(require (for-label scribble/html-render))
|
||||
(define id @racket[render-mixin])))
|
||||
(begin
|
||||
(require (for-label scribble/html-render))
|
||||
(define id @racket[render-mixin])))
|
||||
(def-render-mixin html:render-mixin))
|
||||
|
||||
@title[#:tag "renderer"]{Renderers}
|
||||
|
|
|
@ -77,7 +77,7 @@ documentation expressions.}
|
|||
(code:line keyword contract-expr)]
|
||||
[optional contract-expr
|
||||
(code:line keyword contract-expr)])]{
|
||||
|
||||
|
||||
When used in @racket[provide/doc], exports @racket[id] with the
|
||||
contract described by @racket[contract]
|
||||
just like using @racket[provide/contract].
|
||||
|
@ -109,7 +109,7 @@ form.}
|
|||
(->i (arg ...) () res)
|
||||
(->i (arg ...) () #:pre (pre-id ...) condition [name res])
|
||||
(->i (arg ...) () #:rest rest res)
|
||||
|
||||
|
||||
(->d (arg ...) () (values [id result] ...))
|
||||
(->d (arg ...) () #:pre-cond expr (values [id result] ...))
|
||||
(->d (arg ...) () [id result])
|
||||
|
@ -117,9 +117,9 @@ form.}
|
|||
(->d (arg ...) () #:rest id rest [id result])])]{
|
||||
|
||||
Like @racket[proc-doc], but supporting contract forms that embed
|
||||
argument names. Only a subset of @racket[->i] and @racket[->d] forms are currently
|
||||
supported.}
|
||||
|
||||
argument names. Only a subset of @racket[->i] and @racket[->d] forms are
|
||||
currently supported.}
|
||||
|
||||
@defform[(thing-doc id contract-expr dec-expr)]{
|
||||
|
||||
Like @racket[proc-doc], but for an export of an arbitrary value.}
|
||||
|
|
|
@ -161,7 +161,6 @@ locations, instead of copying to the directory of @racket[dest].}
|
|||
|
||||
Transfers cross-reference information to @racket[ci], which is the
|
||||
initially collected information from @racket[renderer].}
|
||||
|
||||
|
||||
|
||||
@defproc[(xref-index [xref xref?]) (listof entry?)]{
|
||||
|
|
|
@ -328,7 +328,7 @@ but not hollow (using @racket[disk], not @racket[circle]).
|
|||
@defthing[o-bullet pict?]{
|
||||
|
||||
A hollow bullet used by default by @racket[subitem].
|
||||
|
||||
|
||||
It's implementation is:
|
||||
@racketblock[(baseless
|
||||
(cc-superimpose
|
||||
|
|
|
@ -640,7 +640,7 @@ Check Syntax is a part of the DrRacket collection, but is implemented via the to
|
|||
}
|
||||
|
||||
@definterface[syncheck-annotations<%> ()]{
|
||||
|
||||
|
||||
Classes implementing this interface are
|
||||
accceptors of information about a traversal
|
||||
of syntax objects. See @racket[make-traversal].
|
||||
|
@ -682,7 +682,7 @@ Check Syntax is a part of the DrRacket collection, but is implemented via the to
|
|||
Called to indicate that there is a @racket[require] at the location from @racket[start] to @racket[end],
|
||||
and that it corresponds to @racket[file]. Check Syntax adds a popup menu.
|
||||
}
|
||||
|
||||
|
||||
@defmethod[(syncheck:add-docs-menu [source-obj (not/c #f)]
|
||||
[start exact-nonnegative-integer?]
|
||||
[end exact-nonnegative-integer?]
|
||||
|
|
|
@ -150,12 +150,12 @@ Calls the definitions text's
|
|||
@defmethod[#:mode public-final
|
||||
(remove-bkg-running-color [id symbol?])
|
||||
void?]{
|
||||
|
||||
|
||||
Removes the color and label added with @racket[id].
|
||||
|
||||
|
||||
See also @method[drracket:unit:tab<%> add-bkg-running-color].
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -599,7 +599,7 @@ Returns the currently active tab.
|
|||
}
|
||||
|
||||
@defmethod[(get-tab-count) exact-positive-integer?]{
|
||||
Returns the number of open tabs in the frame.
|
||||
Returns the number of open tabs in the frame.
|
||||
}
|
||||
|
||||
@defmethod[(open-in-new-tab [filename (or/c path-string? #f)]) void?]{
|
||||
|
|
|
@ -72,25 +72,25 @@ language [*]:
|
|||
(define-values (f)
|
||||
(with-continuation-mark "#<debug-key-struct>"
|
||||
(#%plain-lambda () (#%plain-app "#<procedure:...rivate/marks.rkt:70:2>"))
|
||||
(#%plain-app
|
||||
(#%plain-app
|
||||
call-with-values
|
||||
(#%plain-lambda ()
|
||||
(#%plain-lambda ()
|
||||
(with-continuation-mark "#<debug-key-struct>"
|
||||
(#%plain-lambda () (#%plain-app
|
||||
(#%plain-lambda () (#%plain-app
|
||||
"#<procedure:...rivate/marks.rkt:70:2>"
|
||||
(#%plain-lambda () beginner:+)))
|
||||
(#%plain-app
|
||||
"#<procedure:closure-storing-proc>"
|
||||
(#%plain-lambda (x)
|
||||
(begin
|
||||
(let-values (((arg0-1643 arg1-1644 arg2-1645)
|
||||
(#%plain-lambda (x)
|
||||
(begin
|
||||
(let-values ([(arg0-1643 arg1-1644 arg2-1645)
|
||||
(#%plain-app
|
||||
values
|
||||
"#<*unevaluated-struct*>"
|
||||
"#<*unevaluated-struct*>"
|
||||
"#<*unevaluated-struct*>")))
|
||||
"#<*unevaluated-struct*>")])
|
||||
(with-continuation-mark "#<debug-key-struct>"
|
||||
(#%plain-lambda ()
|
||||
(#%plain-lambda ()
|
||||
(#%plain-app
|
||||
"#<procedure:...rivate/marks.rkt:70:2>"
|
||||
(#%plain-lambda () beginner:+)
|
||||
|
@ -161,12 +161,12 @@ language [*]:
|
|||
#f
|
||||
(#%plain-lambda () (#%plain-app list f))))))))
|
||||
|
||||
(let-values (((done-already?) (quote #f)))
|
||||
(#%app dynamic-wind void
|
||||
(let-values ([(done-already?) (quote #f)])
|
||||
(#%app dynamic-wind void
|
||||
(lambda () (#%app dynamic-require (quote (quote #%htdp)) (quote #f)))
|
||||
(lambda () (if done-already?
|
||||
(lambda () (if done-already?
|
||||
(#%app void)
|
||||
(let-values ()
|
||||
(let-values ()
|
||||
(set! done-already? (quote #t))
|
||||
(#%app test*)
|
||||
(#%app current-namespace
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
@(require "common.rkt" (for-label syntax/kerncase))
|
||||
|
||||
@(define-syntax-rule (intro id)
|
||||
(begin
|
||||
(require (for-label mzscheme))
|
||||
(define id (racket if))))
|
||||
(begin
|
||||
(require (for-label mzscheme))
|
||||
(define id (racket if))))
|
||||
@(intro mzscheme-if)
|
||||
|
||||
@; ----------------------------------------------------------------------
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
|
||||
@(begin
|
||||
(define the-eval
|
||||
(parameterize ((sandbox-output 'string)
|
||||
(sandbox-error-output 'string))
|
||||
(parameterize ([sandbox-output 'string]
|
||||
[sandbox-error-output 'string])
|
||||
(make-evaluator 'racket/base #:requires '(syntax/keyword))))
|
||||
;;(void (the-eval '(error-print-source-location #f)))
|
||||
(define-syntax-rule (myexamples e ...)
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
read-syntax-inside read-inside)))
|
||||
|
||||
@(begin
|
||||
(define-syntax-rule (define-mb name)
|
||||
(begin
|
||||
(require (for-label scheme/base))
|
||||
(define name @racket[#%module-begin])))
|
||||
(define-mb scheme-#%module-begin))
|
||||
(define-syntax-rule (define-mb name)
|
||||
(begin
|
||||
(require (for-label scheme/base))
|
||||
(define name @racket[#%module-begin])))
|
||||
(define-mb scheme-#%module-begin))
|
||||
|
||||
@(define guide-doc '(lib "scribblings/guide/guide.scrbl"))
|
||||
|
||||
|
|
|
@ -23,11 +23,11 @@ the parameter expressions.
|
|||
[(_ ((p v:expr) ...) body:expr)
|
||||
#:declare p (expr/c #'parameter?
|
||||
#:name "parameter argument")
|
||||
#'(parameterize ((p.c v) ...) body)]))
|
||||
(myparameterize ((current-input-port
|
||||
(open-input-string "(1 2 3)")))
|
||||
#'(parameterize ([p.c v] ...) body)]))
|
||||
(myparameterize ([current-input-port
|
||||
(open-input-string "(1 2 3)")])
|
||||
(read))
|
||||
(myparameterize (('whoops 'something))
|
||||
(myparameterize (['whoops 'something])
|
||||
'whatever)
|
||||
]
|
||||
|
||||
|
|
|
@ -197,9 +197,9 @@ Unlike @racket[scene+curve], if the line passes outside of @racket[image], the i
|
|||
(beside empty-image
|
||||
(rectangle 10 10 "solid" "red")))]
|
||||
}
|
||||
|
||||
|
||||
@section{Polygons}
|
||||
|
||||
|
||||
@defproc*[([(triangle [side-length (and/c real? (not/c negative?))]
|
||||
[mode mode?]
|
||||
[color image-color?])
|
||||
|
@ -423,8 +423,7 @@ They all construct a triangle oriented as follows:
|
|||
(triangle/saa 200 90 40 "solid" "aquamarine")
|
||||
(triangle/saa 40 130 40 "solid" "lightseagreen")]
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@defproc*[([(square [side-len (and/c real? (not/c negative?))]
|
||||
[mode mode?]
|
||||
|
@ -540,7 +539,7 @@ other. The top and bottom pair of angles is @racket[angle] and the left and righ
|
|||
[outline-mode (or/c 'outline "outline")]
|
||||
[pen-or-color (or/c pen? image-color?)])
|
||||
image?])]{
|
||||
|
||||
|
||||
Constructs a star-like polygon where the star is specified by two radii and a number of points.
|
||||
The first radius determines where the points begin, the second determines where they end, and
|
||||
the @racket[point-count] argument determines how many points the star has.
|
||||
|
@ -569,7 +568,7 @@ the @racket[point-count] argument determines how many points the star has.
|
|||
(regular-polygon 20 8 "solid" "red")]
|
||||
}
|
||||
|
||||
|
||||
|
||||
@defproc*[([(polygon [vertices (listof real-valued-posn?)]
|
||||
[mode mode?]
|
||||
[color image-color?])
|
||||
|
@ -656,8 +655,7 @@ the @racket[point-count] argument determines how many points the star has.
|
|||
(rectangle 30 30 "solid" "seagreen")
|
||||
(rectangle 40 40 "solid" "silver")
|
||||
(rectangle 50 50 "solid" "seagreen"))]
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@defproc[(overlay/offset [i1 image?] [x real?] [y real?] [i2 image?]) image?]{
|
||||
|
@ -776,8 +774,7 @@ the @racket[point-count] argument determines how many points the star has.
|
|||
(rectangle 40 40 50 "seagreen")
|
||||
(rectangle 30 30 50 "seagreen")
|
||||
(rectangle 20 20 50 "seagreen"))]
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -868,8 +865,7 @@ the @racket[point-count] argument determines how many points the star has.
|
|||
(ellipse 20 50 "solid" "darkgray")
|
||||
(ellipse 20 30 "solid" "dimgray")
|
||||
(ellipse 20 10 "solid" "black"))]
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@defproc[(beside/align [y-place y-place?] [i1 image?] [i2 image?] [is image?] ...) image?]{
|
||||
|
@ -883,18 +879,17 @@ the @racket[point-count] argument determines how many points the star has.
|
|||
(ellipse 20 50 "solid" "mediumslateblue")
|
||||
(ellipse 20 30 "solid" "slateblue")
|
||||
(ellipse 20 10 "solid" "navy"))
|
||||
|
||||
|
||||
(beside/align "top"
|
||||
(ellipse 20 70 "solid" "mediumorchid")
|
||||
(ellipse 20 50 "solid" "darkorchid")
|
||||
(ellipse 20 30 "solid" "purple")
|
||||
(ellipse 20 10 "solid" "indigo"))
|
||||
|
||||
|
||||
(beside/align "baseline"
|
||||
(text "ijy" 18 "black")
|
||||
(text "ijy" 24 "black"))]
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -906,8 +901,7 @@ the @racket[point-count] argument determines how many points the star has.
|
|||
(ellipse 50 20 "solid" "darkgray")
|
||||
(ellipse 30 20 "solid" "dimgray")
|
||||
(ellipse 10 20 "solid" "black"))]
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@defproc[(above/align [x-place x-place?] [i1 image?] [i2 image?] [is image?] ...) image?]{
|
||||
|
@ -921,14 +915,13 @@ the @racket[point-count] argument determines how many points the star has.
|
|||
(ellipse 50 20 "solid" "goldenrod")
|
||||
(ellipse 30 20 "solid" "darkgoldenrod")
|
||||
(ellipse 10 20 "solid" "sienna"))
|
||||
|
||||
|
||||
(above/align "left"
|
||||
(ellipse 70 20 "solid" "yellowgreen")
|
||||
(ellipse 50 20 "solid" "olivedrab")
|
||||
(ellipse 30 20 "solid" "darkolivegreen")
|
||||
(ellipse 10 20 "solid" "darkgreen"))]
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@section{Placing Images & Scenes}
|
||||
|
@ -937,11 +930,11 @@ Placing images into scenes is particularly useful when building worlds
|
|||
and universes using @racket[2htdp/universe].
|
||||
|
||||
@defproc*[([(empty-scene [width (and/c real? (not/c negative?))]
|
||||
[height (and/c real? (not/c negative?))])
|
||||
image?]
|
||||
[height (and/c real? (not/c negative?))])
|
||||
image?]
|
||||
[(empty-scene [width (and/c real? (not/c negative?))]
|
||||
[height (and/c real? (not/c negative?))]
|
||||
[color image-color?])
|
||||
[color image-color?])
|
||||
image?])]{
|
||||
|
||||
Creates an empty scene, i.e., a white rectangle with a black outline.
|
||||
|
@ -1071,14 +1064,14 @@ the parts that fit onto @racket[scene].
|
|||
20 10 0 1/2
|
||||
20 90 0 1/2
|
||||
"white")
|
||||
|
||||
|
||||
(scene+curve (rectangle 100 100 "solid" "black")
|
||||
-20 -20 0 1
|
||||
120 120 0 1
|
||||
"red")]
|
||||
}
|
||||
|
||||
|
||||
|
||||
@section{Rotating, Scaling, Flipping, Cropping, and Framing Images}
|
||||
|
||||
@defproc[(rotate [angle angle?] [image image?]) image?]{
|
||||
|
@ -1200,11 +1193,12 @@ more expensive than with the other shapes.
|
|||
@defform/subs[(bitmap bitmap-spec)
|
||||
([bitmap-spec rel-string
|
||||
id])]{
|
||||
|
||||
Loads the bitmap specified by @racket[bitmap-spec]. If @racket[bitmap-spec] is a string, it is treated as a
|
||||
relative path. If it is an identifier, it is treated like a require spec and used to refer to a file
|
||||
in a collection.
|
||||
|
||||
|
||||
Loads the bitmap specified by @racket[bitmap-spec]. If
|
||||
@racket[bitmap-spec] is a string, it is treated as a relative path.
|
||||
If it is an identifier, it is treated like a require spec and used to
|
||||
refer to a file in a collection.
|
||||
|
||||
@image-examples[(bitmap icons/stop-16x16.png)
|
||||
(bitmap icons/b-run.png)]
|
||||
}
|
||||
|
@ -1216,7 +1210,7 @@ more expensive than with the other shapes.
|
|||
you may find it simpler to download the image once with a browser
|
||||
and then paste it into your program or download it and use @racket[bitmap].
|
||||
}
|
||||
|
||||
|
||||
@defproc[(image->color-list [image image?]) (listof color?)]{
|
||||
Returns a list of colors that correspond to the colors in the
|
||||
image, reading from left to right, top to bottom.
|
||||
|
@ -1271,7 +1265,7 @@ more expensive than with the other shapes.
|
|||
|
||||
@defproc[(image-width [i image?]) (and/c integer? (not/c negative?) exact?)]{
|
||||
Returns the width of @racket[i].
|
||||
|
||||
|
||||
@image-examples[(image-width (ellipse 30 40 "solid" "orange"))
|
||||
(image-width (circle 30 "solid" "orange"))
|
||||
(image-width (beside (circle 20 "solid" "orange")
|
||||
|
@ -1356,7 +1350,7 @@ This section lists predicates for the basic structures provided by the image lib
|
|||
|
||||
The complete list of colors is available in the documentation for
|
||||
@racket[color-database<%>].
|
||||
|
||||
|
||||
}
|
||||
|
||||
@defstruct[color ([red (and/c natural-number/c (<=/c 255))]
|
||||
|
@ -1433,7 +1427,7 @@ Using @racket["pinhole"] or @racket['pinhole] is only allowed when all of the im
|
|||
}
|
||||
|
||||
@defproc[(step-count? [x any/c]) boolean?]{
|
||||
Determines if @racket[x] is an integer greater than or equal to @racket[1].
|
||||
Determines if @racket[x] is an integer greater than or equal to @racket[1].
|
||||
}
|
||||
|
||||
@defproc[(real-valued-posn? [x any/c]) boolean?]{
|
||||
|
@ -1530,7 +1524,7 @@ then the scene argument's pinhole is preserved.
|
|||
@image-examples[(pinhole-y (center-pinhole (rectangle 10 10 "solid" "red")))]
|
||||
}
|
||||
@defproc[(clear-pinhole [image image?]) image?]{
|
||||
Removes a pinhole from @racket[image] (if the image has a pinhole).
|
||||
Removes a pinhole from @racket[image] (if the image has a pinhole).
|
||||
}
|
||||
|
||||
@defproc[(overlay/pinhole [i1 image?] [i2 image?] [is image?] ...) image?]{
|
||||
|
|
|
@ -197,35 +197,35 @@ The other big change concerns key event handling and mouse event
|
|||
@port[
|
||||
@racketblock[
|
||||
(define (change w a-key-event)
|
||||
(cond
|
||||
[(key=? a-key-event 'left)
|
||||
(world-go w -DELTA)]
|
||||
[(key=? a-key-event 'right)
|
||||
(world-go w +DELTA)]
|
||||
[(char? a-key-event)
|
||||
w]
|
||||
[(key=? a-key-event 'up)
|
||||
(world-go w -DELTA)]
|
||||
[(key=? a-key-event 'down)
|
||||
(world-go w +DELTA)]
|
||||
[else
|
||||
w]))]
|
||||
(cond
|
||||
[(key=? a-key-event 'left)
|
||||
(world-go w -DELTA)]
|
||||
[(key=? a-key-event 'right)
|
||||
(world-go w +DELTA)]
|
||||
[(char? a-key-event)
|
||||
w]
|
||||
[(key=? a-key-event 'up)
|
||||
(world-go w -DELTA)]
|
||||
[(key=? a-key-event 'down)
|
||||
(world-go w +DELTA)]
|
||||
[else
|
||||
w]))]
|
||||
@; ---------------------------------
|
||||
@racketblock[
|
||||
(define (change w a-key-event)
|
||||
(cond
|
||||
[(key=? a-key-event "left")
|
||||
(world-go w -DELTA)]
|
||||
[(key=? a-key-event "right")
|
||||
(world-go w +DELTA)]
|
||||
[(= (string-length a-key-event) 1)
|
||||
w]
|
||||
[(key=? a-key-event "up")
|
||||
(world-go w -DELTA)]
|
||||
[(key=? a-key-event "down")
|
||||
(world-go w +DELTA)]
|
||||
[else
|
||||
w]))
|
||||
(cond
|
||||
[(key=? a-key-event "left")
|
||||
(world-go w -DELTA)]
|
||||
[(key=? a-key-event "right")
|
||||
(world-go w +DELTA)]
|
||||
[(= (string-length a-key-event) 1)
|
||||
w]
|
||||
[(key=? a-key-event "up")
|
||||
(world-go w -DELTA)]
|
||||
[(key=? a-key-event "down")
|
||||
(world-go w +DELTA)]
|
||||
[else
|
||||
w]))
|
||||
]]
|
||||
Note how the @racket[char?] clause changed. Since all chars are now
|
||||
represented as strings containing one ``letter'', the program on the right
|
||||
|
|
|
@ -27,18 +27,17 @@ Example:
|
|||
@(begin
|
||||
#reader scribble/comment-reader
|
||||
(racketblock
|
||||
;; Advanced
|
||||
;; Advanced
|
||||
(define (make-model dir)
|
||||
(lambda (b e)
|
||||
(begin
|
||||
(view dir)
|
||||
(printf "~a ~n" (control)))))
|
||||
(lambda (b e)
|
||||
(begin
|
||||
(view dir)
|
||||
(printf "~a ~n" (control)))))
|
||||
|
||||
(connect
|
||||
(make-model "left")
|
||||
(make-model "right")
|
||||
(make-model "up")
|
||||
(make-model "down"))
|
||||
(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.
|
||||
|
|
|
@ -82,11 +82,11 @@ Example 2:
|
|||
;; 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)))))))
|
||||
(define w
|
||||
(create-window
|
||||
(list
|
||||
(list text1)
|
||||
(list msg1)
|
||||
(list (make-button "OKAY" respond)
|
||||
(make-button "QUIT" (lambda (e) (hide-window w)))))))
|
||||
))
|
||||
|
|
|
@ -53,9 +53,9 @@ Accepts at least two value-producing expressions. Structurally compares the firs
|
|||
value to each value subsequent value specified.
|
||||
|
||||
It is an error to produce a function value.}
|
||||
|
||||
|
||||
@defform[(check-range (test number/c) (min number/c) (max number/c))]{
|
||||
|
||||
|
||||
Accepts three number-producing expressions. Performs the following comparison:
|
||||
min <= test <= max.}
|
||||
|
||||
|
|
|
@ -33,23 +33,28 @@ This module provides a macro for regular expression compilation.
|
|||
(dseq pat re-pat)
|
||||
pat])]{
|
||||
Compiles a regular expression over match patterns to a @racket[machine].
|
||||
|
||||
The interpretation of the pattern language is mostly intuitive. The pattern language may be extended
|
||||
with @racket[define-re-transformer]. @racket[dseq] allows bindings of the @racket[match] pattern to be
|
||||
used in the rest of the regular expression. (Thus, they are not @emph{really} regular expressions.)
|
||||
@racket[unquote] escapes to Racket to evaluate an expression that evaluates to a regular expression (this happens
|
||||
once, at compile time.) @racket[rec] binds a Racket identifier to a delayed version of the inner expression; even
|
||||
if the expression is initially accepting, this delayed version is never accepting.
|
||||
|
||||
The compiler will use an NFA, provided @racket[complement] and @racket[dseq] are not used. Otherwise,
|
||||
many NFAs connected with the machine simulation functions from @racketmodname[unstable/automata/machine] are used.
|
||||
|
||||
The interpretation of the pattern language is mostly intuitive. The
|
||||
pattern language may be extended with @racket[define-re-transformer].
|
||||
@racket[dseq] allows bindings of the @racket[match] pattern to be used
|
||||
in the rest of the regular expression. (Thus, they are not
|
||||
@emph{really} regular expressions.) @racket[unquote] escapes to Racket
|
||||
to evaluate an expression that evaluates to a regular expression (this
|
||||
happens once, at compile time.) @racket[rec] binds a Racket identifier
|
||||
to a delayed version of the inner expression; even if the expression is
|
||||
initially accepting, this delayed version is never accepting.
|
||||
|
||||
The compiler will use an NFA, provided @racket[complement] and
|
||||
@racket[dseq] are not used. Otherwise, many NFAs connected with the
|
||||
machine simulation functions from
|
||||
@racketmodname[unstable/automata/machine] are used.
|
||||
}
|
||||
|
||||
|
||||
@(define-syntax-rule (defidforms (id ...) . dat)
|
||||
(deftogether ((defidform id) ...) . dat))
|
||||
|
||||
|
||||
@defidforms[(complement seq union star epsilon nullset dseq rec)]{
|
||||
Bindings for use in @racket[re].
|
||||
Bindings for use in @racket[re].
|
||||
}
|
||||
|
||||
@defform[(define-re-transformer id expr)]{
|
||||
|
@ -127,9 +132,9 @@ This module provides a few transformers that extend the syntax of regular expres
|
|||
[(list "B")])
|
||||
|
||||
(define-re-transformer my-opt
|
||||
(syntax-rules ()
|
||||
[(_ pat)
|
||||
(union epsilon pat)]))
|
||||
(syntax-rules ()
|
||||
[(_ pat)
|
||||
(union epsilon pat)]))
|
||||
|
||||
(test-re (my-opt "A")
|
||||
[(list)
|
||||
|
|
|
@ -23,19 +23,27 @@
|
|||
[prop:name identifier?]
|
||||
[name? identifier?]
|
||||
[method identifier?])]{
|
||||
|
||||
Defines @racket[name] as a transformer binding for the static information about a new generic group.
|
||||
|
||||
Defines @racket[prop:name] as a structure
|
||||
type property. Structure types implementing this generic group should have this property where the value is a vector
|
||||
with one element per @racket[method] where each value is
|
||||
either @racket[#f] or a procedure with the same arity as specified by @racket[kw-formals*].
|
||||
(@racket[kw-formals*] is similar to the @racket[kw-formals] used by @racket[lambda], except no expression is given for optional arguments.)
|
||||
The arity of each method is checked by the guard on the structure type property.
|
||||
Defines @racket[name] as a transformer binding for the static
|
||||
information about a new generic group.
|
||||
|
||||
Defines @racket[name?] as a predicate identifying instances of structure types that implement this generic group.
|
||||
Defines @racket[prop:name] as a structure type property. Structure
|
||||
types implementing this generic group should have this property where
|
||||
the value is a vector with one element per @racket[method] where each
|
||||
value is either @racket[#f] or a procedure with the same arity as
|
||||
specified by @racket[kw-formals*]. (@racket[kw-formals*] is similar to
|
||||
the @racket[kw-formals] used by @racket[lambda], except no expression is
|
||||
given for optional arguments.) The arity of each method is checked by
|
||||
the guard on the structure type property.
|
||||
|
||||
Defines each @racket[method] as a generic procedure that calls the corresponding method on values where @racket[name?] is true. Each method must have a required by-position argument that is @racket[free-identifier=?] to @racket[name]. This argument is used in the generic definition to locate the specialization.
|
||||
Defines @racket[name?] as a predicate identifying instances of structure
|
||||
types that implement this generic group.
|
||||
|
||||
Defines each @racket[method] as a generic procedure that calls the
|
||||
corresponding method on values where @racket[name?] is true. Each method
|
||||
must have a required by-position argument that is
|
||||
@racket[free-identifier=?] to @racket[name]. This argument is used in
|
||||
the generic definition to locate the specialization.
|
||||
|
||||
}
|
||||
|
||||
|
@ -56,36 +64,43 @@ where @racket[_prop:name] and @racket[_name?] are created with the lexical
|
|||
context of @racket[name].
|
||||
|
||||
}
|
||||
|
||||
|
||||
@defform[(define-methods name definition ...)
|
||||
#:contracts
|
||||
([name identifier?])]{
|
||||
|
||||
@racket[name] must be a transformer binding for the static information about a new generic group.
|
||||
|
||||
Expands to a value usable as the property value for the structure type property of the @racket[name] generic group.
|
||||
|
||||
If the @racket[definition]s define the methods of @racket[name], then they are used in the property value.
|
||||
@racket[name] must be a transformer binding for the static information
|
||||
about a new generic group.
|
||||
|
||||
If any method of @racket[name] is not defined, then @racket[#f] is used to signify that the structure type does not implement the particular method.
|
||||
Expands to a value usable as the property value for the structure type
|
||||
property of the @racket[name] generic group.
|
||||
|
||||
If the @racket[definition]s define the methods of @racket[name], then
|
||||
they are used in the property value.
|
||||
|
||||
If any method of @racket[name] is not defined, then @racket[#f] is used
|
||||
to signify that the structure type does not implement the particular
|
||||
method.
|
||||
|
||||
Allows @racket[define/generic] to appear in @racket[definition ...].
|
||||
|
||||
}
|
||||
|
||||
|
||||
@defform[(define/generic local-name method-name)
|
||||
#:contracts
|
||||
([local-name identifier?]
|
||||
[method-name identifier?])]{
|
||||
|
||||
When used inside @racket[define-methods], binds @racket[local-name] to the generic for @racket[method-name]. This is useful for method specializations to use the generic methods on other values.
|
||||
|
||||
|
||||
When used inside @racket[define-methods], binds @racket[local-name] to
|
||||
the generic for @racket[method-name]. This is useful for method
|
||||
specializations to use the generic methods on other values.
|
||||
|
||||
Syntactically an error when used outside @racket[define-methods].
|
||||
|
||||
}
|
||||
|
||||
|
||||
@; Examples
|
||||
@(require scribble/eval)
|
||||
@(require scribble/eval)
|
||||
@(define (new-evaluator)
|
||||
(let* ([e (make-base-eval)])
|
||||
(e '(require (for-syntax racket/base)
|
||||
|
|
|
@ -29,9 +29,18 @@ This library provides a simplified version of parameters that are backed by cont
|
|||
[none-v [any/c #f]]
|
||||
[tag continuation-prompt-tag? default-continuation-prompt-tag])
|
||||
(listof vector?)]{
|
||||
Returns the values of the @racket[mps] up to @racket[tag]. The length of each vector in the result list is the same as the length of @racket[mps], and a value in a particular vector position is the value for the corresponding mark parameter in @racket[mps]. Values for multiple mark parameter appear in a single vector only when the mark parameters are for the same continuation frame in the current continuation. The @racket[none-v] argument is used for vector elements to indicate the lack of a value.
|
||||
}
|
||||
|
||||
Returns the values of the @racket[mps] up to @racket[tag]. The length
|
||||
of each vector in the result list is the same as the length of
|
||||
@racket[mps], and a value in a particular vector position is the value
|
||||
for the corresponding mark parameter in @racket[mps]. Values for
|
||||
multiple mark parameter appear in a single vector only when the mark
|
||||
parameters are for the same continuation frame in the current
|
||||
continuation. The @racket[none-v] argument is used for vector elements
|
||||
to indicate the lack of a value.
|
||||
}
|
||||
|
||||
@defform[(mark-parameterize ([mp expr] ...) body-expr ...)]{
|
||||
Parameterizes @racket[(begin body-expr ...)] by associating each @racket[mp] with the evaluation of @racket[expr] in the parameterization of the entire expression.
|
||||
}
|
||||
Parameterizes @racket[(begin body-expr ...)] by associating each
|
||||
@racket[mp] with the evaluation of @racket[expr] in the
|
||||
parameterization of the entire expression.
|
||||
}
|
||||
|
|
|
@ -40,16 +40,16 @@ The other arguments have the same meaning as for @racket[expr/c].
|
|||
@examples[#:eval the-eval
|
||||
(define-syntax (myparameterize1 stx)
|
||||
(syntax-case stx ()
|
||||
[(_ ((p v)) body)
|
||||
[(_ ([p v]) body)
|
||||
(with-syntax ([cp (wrap-expr/c
|
||||
#'parameter? #'p
|
||||
#:name "the parameter argument"
|
||||
#:context stx)])
|
||||
#'(parameterize ((cp v)) body))]))
|
||||
(myparameterize1 ((current-input-port
|
||||
(open-input-string "(1 2 3)")))
|
||||
#'(parameterize ([cp v]) body))]))
|
||||
(myparameterize1 ([current-input-port
|
||||
(open-input-string "(1 2 3)")])
|
||||
(read))
|
||||
(myparameterize1 (('whoops 'something))
|
||||
(myparameterize1 (['whoops 'something])
|
||||
'whatever)
|
||||
|
||||
(module mod racket
|
||||
|
|
|
@ -7,20 +7,21 @@
|
|||
web-server/lang/serial-lambda
|
||||
web-server/private/define-closure))
|
||||
|
||||
|
||||
The defunctionalization process of the Web Language (see @secref["stateless" #:doc '(lib "web-server/scribblings/web-server.scrbl")])
|
||||
The defunctionalization process of the Web Language (see
|
||||
@secref["stateless" #:doc '(lib "web-server/scribblings/web-server.scrbl")])
|
||||
requires an explicit representation of closures that is serializable.
|
||||
|
||||
@defmodule[web-server/lang/serial-lambda]{
|
||||
|
||||
|
||||
@defform[(serial-lambda formals body ...)]{
|
||||
Returns @racket[(lambda formals body ...)], except it is serializable.
|
||||
Returns @racket[(lambda formals body ...)], except it is serializable.
|
||||
}
|
||||
|
||||
|
||||
@defform[(serial-case-lambda [formals body ...] ...)]{
|
||||
Returns @racket[(case-lambda [formals body ...] ...)], except it is serializable.
|
||||
Returns @racket[(case-lambda [formals body ...] ...)], except it is
|
||||
serializable.
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@section[#:style 'hidden]{Definition Syntax}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
web-server/servlet))
|
||||
|
||||
@defmodule[web-server/servlet/servlet-structs]{
|
||||
|
||||
|
||||
Servlets communicate to the Web Server by returning HTTP responses. In order to
|
||||
accommodate lightweight programs (and backwards compatibility), the Web Server
|
||||
provides an indirection from application-specific response formats and the internal
|
||||
|
|
|
@ -17,14 +17,15 @@
|
|||
|
||||
@defproc[(make-cached-url->servlet
|
||||
[url->path url->path/c]
|
||||
[path->serlvet path->servlet/c])
|
||||
[path->serlvet path->servlet/c])
|
||||
(values (-> void)
|
||||
url->servlet/c)]{
|
||||
The first return value flushes the cache.
|
||||
The second is a procedure that uses @racket[url->path] to resolve the URL to a path, then uses @racket[path->servlet] to resolve
|
||||
that path to a servlet, caching the results in an internal table.
|
||||
The first return value flushes the cache. The second is a procedure
|
||||
that uses @racket[url->path] to resolve the URL to a path, then uses
|
||||
@racket[path->servlet] to resolve that path to a servlet, caching the
|
||||
results in an internal table.
|
||||
}
|
||||
|
||||
|
||||
@defproc[(make [url->servlet url->servlet/c]
|
||||
[#:responders-servlet-loading
|
||||
responders-servlet-loading
|
||||
|
@ -35,11 +36,14 @@
|
|||
(url? exn? . -> . can-be-response?)
|
||||
servlet-error-responder])
|
||||
dispatcher/c]{
|
||||
This dispatcher runs racket servlets, using @racket[url->servlet] to resolve URLs to the underlying servlets.
|
||||
If servlets have errors loading, then @racket[responders-servlet-loading] is used. Other errors are handled with
|
||||
@racket[responders-servlet]. If a servlet raises calls @racket[next-dispatcher], then the signal is propagated by this dispatcher.
|
||||
This dispatcher runs racket servlets, using @racket[url->servlet] to
|
||||
resolve URLs to the underlying servlets. If servlets have errors
|
||||
loading, then @racket[responders-servlet-loading] is used. Other errors
|
||||
are handled with @racket[responders-servlet]. If a servlet raises calls
|
||||
@racket[next-dispatcher], then the signal is propagated by this
|
||||
dispatcher.
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@include-section["servlet-setup.scrbl"]
|
||||
|
@ -48,18 +52,18 @@
|
|||
|
||||
@section{Internal Servlet Representation}
|
||||
|
||||
@defmodule[web-server/private/servlet]{
|
||||
@defstruct[servlet ([custodian custodian?]
|
||||
[namespace namespace?]
|
||||
[manager manager?]
|
||||
[directory path-string?]
|
||||
[handler (request? . -> . can-be-response?)])
|
||||
#:mutable]{
|
||||
Instances of this structure hold the necessary parts of a servlet:
|
||||
the @racket[custodian] responsible for the servlet's resources,
|
||||
the @racket[namespace] the servlet is executed within,
|
||||
the @racket[manager] responsible for the servlet's continuations,
|
||||
the current @racket[directory] of the servlet,
|
||||
and the @racket[handler] for all requests to the servlet.
|
||||
}
|
||||
@defmodule[web-server/private/servlet]{
|
||||
@defstruct[servlet ([custodian custodian?]
|
||||
[namespace namespace?]
|
||||
[manager manager?]
|
||||
[directory path-string?]
|
||||
[handler (request? . -> . can-be-response?)])
|
||||
#:mutable]{
|
||||
Instances of this structure hold the necessary parts of a servlet:
|
||||
the @racket[custodian] responsible for the servlet's resources,
|
||||
the @racket[namespace] the servlet is executed within,
|
||||
the @racket[manager] responsible for the servlet's continuations,
|
||||
the current @racket[directory] of the servlet,
|
||||
and the @racket[handler] for all requests to the servlet.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,16 +98,18 @@ URLs to paths on the filesystem.
|
|||
This is primarily useful for dispatchers that allow path information after
|
||||
the name of a service to be used for data, but where the service is represented
|
||||
by a file. The most prominent example is obviously servlets.}
|
||||
|
||||
|
||||
@defproc[(filter-url->path [regex regexp?]
|
||||
[url->path url->path/c])
|
||||
url->path/c]{
|
||||
Runs the underlying @racket[url->path] but will only return if the path, when considered as a string,
|
||||
matches the @racket[regex]. This is useful to disallow strange files, like GIFs, from being considered
|
||||
servlets when using the servlet dispatchers. It will return a @racket[exn:fail:filesystem:exists?] exception if
|
||||
the path does not match.
|
||||
Runs the underlying @racket[url->path] but will only return if the
|
||||
path, when considered as a string, matches the @racket[regex]. This is
|
||||
useful to disallow strange files, like GIFs, from being considered
|
||||
servlets when using the servlet dispatchers. It will return a
|
||||
@racket[exn:fail:filesystem:exists?] exception if the path does not
|
||||
match.
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@; ------------------------------------------------------------
|
||||
|
@ -249,35 +251,37 @@ a URL that refreshes the password file, servlet cache, etc.}
|
|||
web-server/configuration/responders))
|
||||
|
||||
@defthing[denied?/c contract?]{
|
||||
Equivalent to @racket[(request? . -> . (or/c false/c string?))].
|
||||
The return is the authentication realm as a string if the request is not authorized and
|
||||
@racket[#f] if the request @emph{is} authorized.
|
||||
}
|
||||
|
||||
Equivalent to @racket[(request? . -> . (or/c false/c string?))]. The
|
||||
return is the authentication realm as a string if the request is not
|
||||
authorized and @racket[#f] if the request @emph{is} authorized.
|
||||
}
|
||||
|
||||
@defproc[(make [denied? denied?/c]
|
||||
[#:authentication-responder
|
||||
authentication-responder
|
||||
(url? header? . -> . response?)
|
||||
(gen-authentication-responder "forbidden.html")])
|
||||
dispatcher/c]{
|
||||
A dispatcher that checks if the request is denied based on @racket[denied?]. If so, then
|
||||
@racket[authentication-responder] is called with a @racket[header] that
|
||||
requests credentials. If not, then @racket[next-dispatcher] is
|
||||
invoked.
|
||||
A dispatcher that checks if the request is denied based on
|
||||
@racket[denied?]. If so, then @racket[authentication-responder] is
|
||||
called with a @racket[header] that requests credentials. If not, then
|
||||
@racket[next-dispatcher] is invoked.
|
||||
}
|
||||
|
||||
|
||||
@defthing[authorized?/c contract?]{
|
||||
Equivalent to @racket[(string? (or/c false/c bytes?) (or/c false/c bytes?) . -> . (or/c false/c string?))].
|
||||
The input is the URI as a string and the username and passwords as bytes.
|
||||
The return is the authentication realm as a string if the user is not authorized and
|
||||
@racket[#f] if the request @emph{is} authorized.
|
||||
}
|
||||
|
||||
Equivalent to
|
||||
@racket[(string? (or/c false/c bytes?) (or/c false/c bytes?) . -> . (or/c false/c string?))].
|
||||
The input is the URI as a string and the username and passwords as
|
||||
bytes. The return is the authentication realm as a string if the user
|
||||
is not authorized and @racket[#f] if the request @emph{is} authorized.
|
||||
}
|
||||
|
||||
@defproc[(make-basic-denied?/path [password-file path-string?])
|
||||
(values (-> void)
|
||||
authorized?/c)]{
|
||||
Creates an authorization procedure based on the given password file. The first returned value
|
||||
is a procedure that refreshes the password cache used by the authorization procedure.
|
||||
Creates an authorization procedure based on the given password
|
||||
file. The first returned value is a procedure that refreshes the
|
||||
password cache used by the authorization procedure.
|
||||
|
||||
@racket[password-file] is parsed as:
|
||||
@racketblock[(list ([domain : string?]
|
||||
|
@ -361,14 +365,14 @@ a URL that refreshes the password file, servlet cache, etc.}
|
|||
If @racket[over-limit] is @racket['kill-old], then the oldest request handler is killed---prioritizing new connections over old.
|
||||
(This setting is a little dangerous because requests might never finish if there is constant load.)
|
||||
}}
|
||||
|
||||
|
||||
@(require (for-label
|
||||
web-server/web-server
|
||||
web-server/http
|
||||
(prefix-in limit: web-server/dispatchers/limit)
|
||||
(prefix-in filter: web-server/dispatchers/dispatch-filter)
|
||||
(prefix-in sequencer: web-server/dispatchers/dispatch-sequencer)))
|
||||
|
||||
|
||||
Consider this example:
|
||||
@racketmod[
|
||||
racket
|
||||
|
|
|
@ -23,9 +23,8 @@ Suppose we want to create an abstraction of entering a date in an HTML form. The
|
|||
@racketblock[
|
||||
(define date-formlet
|
||||
(formlet
|
||||
(div
|
||||
"Month:" ,{input-int . => . month}
|
||||
"Day:" ,{input-int . => . day})
|
||||
(div "Month:" ,{input-int . => . month}
|
||||
"Day:" ,{input-int . => . day})
|
||||
(list month day)))
|
||||
]
|
||||
|
||||
|
@ -203,7 +202,7 @@ types. Refer to @secref["input-formlets"] for example low-level formlets using t
|
|||
(values xexpr-forest/c
|
||||
((listof binding?) . -> . (values (coerce-contract 'formlet/c content) ...))
|
||||
integer?))].
|
||||
|
||||
|
||||
A @tech{formlet}'s internal representation is a function from an initial input number
|
||||
to an @xexpr forest rendering, a processing function, and the next allowable
|
||||
input number.
|
||||
|
@ -233,38 +232,41 @@ types. Refer to @secref["input-formlets"] for example low-level formlets using t
|
|||
|
||||
@defproc[(xml-forest [r xexpr-forest/c])
|
||||
(formlet/c procedure?)]{
|
||||
Constructs a @tech{formlet} with the rendering @racket[r] and the identity procedure as the processing step.
|
||||
Constructs a @tech{formlet} with the rendering @racket[r] and the
|
||||
identity procedure as the processing step.
|
||||
}
|
||||
|
||||
@defproc[(xml [r xexpr/c])
|
||||
(formlet/c procedure?)]{
|
||||
Equivalent to @racket[(xml-forest (list r))].
|
||||
Equivalent to @racket[(xml-forest (list r))].
|
||||
}
|
||||
|
||||
|
||||
@defproc[(text [r string?])
|
||||
(formlet/c procedure?)]{
|
||||
Equivalent to @racket[(xml r)].
|
||||
Equivalent to @racket[(xml r)].
|
||||
}
|
||||
|
||||
|
||||
@defproc[(tag-xexpr [tag symbol?]
|
||||
[attrs (listof (list/c symbol? string?))]
|
||||
[inner (formlet/c any/c)])
|
||||
(formlet/c any/c)]{
|
||||
Constructs a @tech{formlet} with the rendering @racket[(list (list* tag attrs inner-rendering))] where @racket[inner-rendering] is
|
||||
the rendering of @racket[inner] and the processing stage identical to @racket[inner].
|
||||
Constructs a @tech{formlet} with the rendering @racket[(list (list*
|
||||
tag attrs inner-rendering))] where @racket[inner-rendering] is the
|
||||
rendering of @racket[inner] and the processing stage identical to
|
||||
@racket[inner].
|
||||
}
|
||||
|
||||
@defproc[(formlet-display [f (formlet/c any/c)])
|
||||
xexpr-forest/c]{
|
||||
Renders @racket[f].
|
||||
Renders @racket[f].
|
||||
}
|
||||
|
||||
|
||||
@defproc[(formlet-process [f (formlet/c any/c ...)]
|
||||
[r request?])
|
||||
(values any/c ...)]{
|
||||
Runs the processing stage of @racket[f] on the bindings in @racket[r].
|
||||
Runs the processing stage of @racket[f] on the bindings in @racket[r].
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@section[#:tag "input-formlets"]{Predefined Formlets}
|
||||
|
@ -273,81 +275,90 @@ types. Refer to @secref["input-formlets"] for example low-level formlets using t
|
|||
@defmodule[web-server/formlets/input]{
|
||||
|
||||
These @tech{formlet}s are the main combinators for form input.
|
||||
|
||||
|
||||
@defproc[(make-input [render (string? . -> . xexpr/c)])
|
||||
(formlet/c (or/c false/c binding?))]{
|
||||
This @tech{formlet} is rendered with @racket[render], which is passed the input name, and results in the
|
||||
extracted @racket[binding].
|
||||
}
|
||||
|
||||
This @tech{formlet} is rendered with @racket[render], which is passed
|
||||
the input name, and results in the extracted @racket[binding].
|
||||
}
|
||||
|
||||
@defproc[(make-input* [render (string? . -> . xexpr/c)])
|
||||
(formlet/c (listof binding?))]{
|
||||
This @tech{formlet} is rendered with @racket[render], which is passed the input name, and results in all the
|
||||
@racket[binding]s that use the name.
|
||||
This @tech{formlet} is rendered with @racket[render], which is passed
|
||||
the input name, and results in all the @racket[binding]s that use the
|
||||
name.
|
||||
}
|
||||
|
||||
|
||||
@defproc[(text-input [#:value value (or/c false/c bytes?) #f]
|
||||
[#:size size (or/c false/c exact-nonnegative-integer?) #f]
|
||||
[#:max-length max-length (or/c false/c exact-nonnegative-integer?) #f]
|
||||
[#:read-only? read-only? boolean? #f]
|
||||
[#:attributes attrs (listof (list/c symbol? string?)) empty])
|
||||
(formlet/c (or/c false/c binding?))]{
|
||||
This @tech{formlet} renders using an INPUT element with the TEXT type and the attributes given in the arguments.
|
||||
This @tech{formlet} renders using an INPUT element with the TEXT type
|
||||
and the attributes given in the arguments.
|
||||
}
|
||||
|
||||
|
||||
@defproc[(password-input [#:value value (or/c false/c bytes?) #f]
|
||||
[#:size size (or/c false/c exact-nonnegative-integer?) #f]
|
||||
[#:max-length max-length (or/c false/c exact-nonnegative-integer?) #f]
|
||||
[#:read-only? read-only? boolean? #f]
|
||||
[#:attributes attrs (listof (list/c symbol? string?)) empty])
|
||||
(formlet/c (or/c false/c binding?))]{
|
||||
This @tech{formlet} renders using an INPUT element with the PASSWORD type and the attributes given in the arguments.
|
||||
This @tech{formlet} renders using an INPUT element with the PASSWORD
|
||||
type and the attributes given in the arguments.
|
||||
}
|
||||
|
||||
|
||||
@defproc[(textarea-input [#:value value (or/c false/c bytes?) #f]
|
||||
[#:rows rows (or/c false/c number?) #f]
|
||||
[#:cols cols (or/c false/c number?) #f]
|
||||
[#:attributes attrs (listof (list/c symbol? string?)) empty])
|
||||
(formlet/c (or/c false/c binding?))]{
|
||||
This @tech{formlet} renders using an TEXTAREA element with attributes given in the arguments.
|
||||
This @tech{formlet} renders using an TEXTAREA element with attributes
|
||||
given in the arguments.
|
||||
}
|
||||
|
||||
|
||||
@defproc[(checkbox [value bytes?]
|
||||
[checked? boolean?]
|
||||
[#:attributes attrs (listof (list/c symbol? string?)) empty])
|
||||
(formlet/c (or/c false/c binding?))]{
|
||||
This @tech{formlet} renders using an INPUT element with the CHECKBOX type and the attributes given in the arguments.
|
||||
This @tech{formlet} renders using an INPUT element with the CHECKBOX
|
||||
type and the attributes given in the arguments.
|
||||
}
|
||||
|
||||
|
||||
@defproc[(radio [value bytes?]
|
||||
[checked? boolean?]
|
||||
[#:attributes attrs (listof (list/c symbol? string?)) empty])
|
||||
(formlet/c (or/c false/c binding?))]{
|
||||
This @tech{formlet} renders using an INPUT element with the RADIO type and the attributes given in the arguments.
|
||||
}
|
||||
|
||||
@defproc[(submit [value bytes?]
|
||||
|
||||
@defproc[(submit [value bytes?]
|
||||
[#:attributes attrs (listof (list/c symbol? string?)) empty])
|
||||
(formlet/c (or/c false/c binding?))]{
|
||||
This @tech{formlet} renders using an INPUT element with the SUBMIT type and the attributes given in the arguments.
|
||||
This @tech{formlet} renders using an INPUT element with the SUBMIT
|
||||
type and the attributes given in the arguments.
|
||||
}
|
||||
|
||||
|
||||
@defproc[(reset [value bytes?]
|
||||
[#:attributes attrs (listof (list/c symbol? string?)) empty])
|
||||
(formlet/c (or/c false/c binding?))]{
|
||||
This @tech{formlet} renders using an INPUT element with the RESET type and the attributes given in the arguments.
|
||||
This @tech{formlet} renders using an INPUT element with the RESET type
|
||||
and the attributes given in the arguments.
|
||||
}
|
||||
|
||||
@defproc[(file-upload [#:attributes attrs (listof (list/c symbol? string?)) empty])
|
||||
(formlet/c (or/c false/c binding?))]{
|
||||
This @tech{formlet} renders using an INPUT element with the FILE type and the attributes given in the arguments.
|
||||
This @tech{formlet} renders using an INPUT element with the FILE type
|
||||
and the attributes given in the arguments.
|
||||
}
|
||||
|
||||
|
||||
@defproc[(hidden [value bytes?] [#:attributes attrs (listof (list/c symbol? string?)) empty])
|
||||
(formlet/c (or/c false/c binding?))]{
|
||||
This @tech{formlet} renders using an INPUT element with HIDDEN type and the attributes given in the arguments.
|
||||
This @tech{formlet} renders using an INPUT element with HIDDEN type
|
||||
and the attributes given in the arguments.
|
||||
}
|
||||
|
||||
|
||||
@defproc[(img [alt bytes?]
|
||||
[src bytes?]
|
||||
[#:height height (or/c false/c exact-nonnegative-integer?) #f]
|
||||
|
@ -356,25 +367,32 @@ These @tech{formlet}s are the main combinators for form input.
|
|||
[#:width width (or/c false/c exact-nonnegative-integer?) #f]
|
||||
[#:attributes attrs (listof (list/c symbol? string?)) empty])
|
||||
(formlet/c (or/c false/c binding?))]{
|
||||
This @tech{formlet} renders using an IMG element with the attributes given in the arguments.
|
||||
This @tech{formlet} renders using an IMG element with the attributes
|
||||
given in the arguments.
|
||||
}
|
||||
|
||||
|
||||
@defproc[(button [type bytes?]
|
||||
[button-text bytes?]
|
||||
[#:disabled disabled boolean? #f]
|
||||
[#:value value (or/c false/c bytes?) #f]
|
||||
[#:attributes attrs (listof (list/c symbol? string?)) empty])
|
||||
(formlet/c (or/c false/c binding?))]{
|
||||
This @tech{formlet} renders using a BUTTON element with the attributes given in the arguments. @racket[button-text] is the text that will appear on the button when rendered.
|
||||
}
|
||||
|
||||
This @tech{formlet} renders using a BUTTON element with the attributes
|
||||
given in the arguments. @racket[button-text] is the text that will
|
||||
appear on the button when rendered.
|
||||
}
|
||||
|
||||
@defproc[(multiselect-input [l sequence?]
|
||||
[#:attributes attrs (listof (list/c symbol? string?)) empty]
|
||||
[#:multiple? multiple? boolean? #t]
|
||||
[#:selected? selected? (any/c . -> . boolean?) (λ (x) #f)]
|
||||
[#:display display (any/c . -> . xexpr/c) (λ (x) x)])
|
||||
(formlet/c list?)]{
|
||||
This @tech{formlet} renders using an SELECT element with the attributes given with an OPTION for each element of the sequence. If @racket[multiple?] is @racket[#t], then multiple options may be selected. An element is selected if @racket[selected?] returns @racket[#t]. Elements are displayed with @racket[display].
|
||||
This @tech{formlet} renders using an SELECT element with the
|
||||
attributes given with an OPTION for each element of the sequence. If
|
||||
@racket[multiple?] is @racket[#t], then multiple options may be
|
||||
selected. An element is selected if @racket[selected?] returns
|
||||
@racket[#t]. Elements are displayed with @racket[display].
|
||||
}
|
||||
|
||||
@defproc[(select-input [l sequence?]
|
||||
|
@ -382,51 +400,62 @@ These @tech{formlet}s are the main combinators for form input.
|
|||
[#:selected? selected? (any/c . -> . boolean?) (λ (x) #f)]
|
||||
[#:display display (any/c . -> . xexpr/c) (λ (x) x)])
|
||||
(formlet/c any/c)]{
|
||||
This @tech{formlet} renders using an SELECT element with the attributes given with an OPTION for each element of the sequence. An element is selected if @racket[selected?] returns @racket[#t]. Elements are displayed with @racket[display].
|
||||
This @tech{formlet} renders using an SELECT element with the
|
||||
attributes given with an OPTION for each element of the sequence. An
|
||||
element is selected if @racket[selected?] returns
|
||||
@racket[#t]. Elements are displayed with @racket[display].
|
||||
}
|
||||
|
||||
|
||||
@defproc[(required [f (formlet/c (or/c false/c binding?))])
|
||||
(formlet/c bytes?)]{
|
||||
Constructs a @tech{formlet} that extracts the @racket[binding:form-value] from the binding produced by @racket[f], or errors.
|
||||
Constructs a @tech{formlet} that extracts the
|
||||
@racket[binding:form-value] from the binding produced by @racket[f],
|
||||
or errors.
|
||||
}
|
||||
|
||||
@defproc[(default
|
||||
[def bytes?]
|
||||
[f (formlet/c (or/c false/c binding?))])
|
||||
(formlet/c bytes?)]{
|
||||
Constructs a @tech{formlet} that extracts the @racket[binding:form-value] from the binding produced by @racket[f], or returns @racket[def].
|
||||
Constructs a @tech{formlet} that extracts the
|
||||
@racket[binding:form-value] from the binding produced by @racket[f],
|
||||
or returns @racket[def].
|
||||
}
|
||||
|
||||
|
||||
@defproc[(to-string [f (formlet/c bytes?)])
|
||||
(formlet/c string?)]{
|
||||
Converts @racket[f]'s output to a string. Equivalent to @racket[(cross (pure bytes->string/utf-8) f)].
|
||||
}
|
||||
|
||||
Converts @racket[f]'s output to a string. Equivalent to
|
||||
@racket[(cross (pure bytes->string/utf-8) f)].
|
||||
}
|
||||
|
||||
@defproc[(to-number [f (formlet/c string?)])
|
||||
(formlet/c number?)]{
|
||||
Converts @racket[f]'s output to a number. Equivalent to @racket[(cross (pure string->number) f)].
|
||||
}
|
||||
Converts @racket[f]'s output to a number. Equivalent to @racket[(cross
|
||||
(pure string->number) f)].
|
||||
}
|
||||
|
||||
@defproc[(to-symbol [f (formlet/c string?)])
|
||||
(formlet/c symbol?)]{
|
||||
Converts @racket[f]'s output to a symbol. Equivalent to @racket[(cross (pure string->symbol) f)].
|
||||
}
|
||||
Converts @racket[f]'s output to a symbol. Equivalent to
|
||||
@racket[(cross (pure string->symbol) f)].
|
||||
}
|
||||
|
||||
@defproc[(to-boolean [f (formlet/c bytes?)])
|
||||
(formlet/c boolean?)]{
|
||||
Converts @racket[f]'s output to a boolean, if it is equal to @racket[#"on"].
|
||||
Converts @racket[f]'s output to a boolean, if it is equal to
|
||||
@racket[#"on"].
|
||||
}
|
||||
|
||||
|
||||
@defthing[input-string (formlet/c string?)]{
|
||||
Equivalent to @racket[(to-string (required (text-input)))].
|
||||
Equivalent to @racket[(to-string (required (text-input)))].
|
||||
}
|
||||
|
||||
@defthing[input-int (formlet/c integer?)]{
|
||||
Equivalent to @racket[(to-number input-string)].
|
||||
Equivalent to @racket[(to-number input-string)].
|
||||
}
|
||||
|
||||
@defthing[input-symbol (formlet/c symbol?)]{
|
||||
Equivalent to @racket[(to-symbol input-string)].
|
||||
Equivalent to @racket[(to-symbol input-string)].
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -446,16 +475,18 @@ A few utilities are provided for using @tech{formlet}s in Web applications.
|
|||
`(html (head (title "Form Entry"))
|
||||
(body ,form-xexpr)))])
|
||||
(values any/c ...)]{
|
||||
Uses @racket[send/suspend] and @racket[response/xexpr] to send @racket[f]'s rendering (wrapped in a FORM tag whose action is
|
||||
the continuation URL (wrapped again by @racket[wrapper])) to the client.
|
||||
When the form is submitted, the request is passed to the
|
||||
processing stage of @racket[f].
|
||||
Uses @racket[send/suspend] and @racket[response/xexpr] to send
|
||||
@racket[f]'s rendering (wrapped in a FORM tag whose action is the
|
||||
continuation URL (wrapped again by @racket[wrapper])) to the client.
|
||||
When the form is submitted, the request is passed to the processing
|
||||
stage of @racket[f].
|
||||
}
|
||||
|
||||
|
||||
@defproc[(embed-formlet [embed/url ((request? . -> . any) . -> . string?)]
|
||||
[f (formlet/c any/c ...)])
|
||||
xexpr/c]{
|
||||
Like @racket[send/formlet], but for use with @racket[send/suspend/dispatch].
|
||||
Like @racket[send/formlet], but for use with
|
||||
@racket[send/suspend/dispatch].
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -69,12 +69,12 @@ The @web-server implements many HTTP libraries that are provided by this module.
|
|||
|
||||
You are @bold{unlikely to need to construct} a request struct.
|
||||
}
|
||||
|
||||
|
||||
@defproc[(request-bindings/raw [r request?])
|
||||
(listof binding?)]{
|
||||
Forces @racket[(request-bindings/raw-promise r)].
|
||||
}
|
||||
|
||||
|
||||
Here is an example typical of what you will find in many applications:
|
||||
@racketblock[
|
||||
(define (get-number req)
|
||||
|
@ -181,12 +181,12 @@ Here is an example typical of what you will find in many applications:
|
|||
(λ (op) (write-bytes #"Moved" op)))
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@defproc[(response/full [code number?] [message bytes?] [seconds number?] [mime bytes?]
|
||||
[headers (listof header?)] [body (listof bytes?)])
|
||||
response?]{
|
||||
A constructor for responses where @racket[body] is the response body.
|
||||
|
||||
|
||||
Example:
|
||||
@racketblock[
|
||||
(response/full
|
||||
|
@ -261,7 +261,7 @@ transmission that the server @bold{will not catch}.}
|
|||
|
||||
@warning{When using cookies, make sure you follow the advice of the @link["http://cookies.lcs.mit.edu/"]{MIT Cookie Eaters},
|
||||
or you will be susceptible to dangerous attacks.}
|
||||
}
|
||||
}
|
||||
|
||||
@; ------------------------------------------------------------
|
||||
@section[#:tag "cookie-parse"]{Extracting Cookies}
|
||||
|
@ -277,9 +277,10 @@ transmission that the server @bold{will not catch}.}
|
|||
[value string?]
|
||||
[domain (or/c false/c valid-domain?)]
|
||||
[path (or/c false/c string?)])]{
|
||||
|
||||
While server cookies are represented with @racket[cookie?]s, cookies that come from the client are represented
|
||||
with a @racket[client-cookie] structure.
|
||||
|
||||
While server cookies are represented with @racket[cookie?]s, cookies
|
||||
that come from the client are represented with a
|
||||
@racket[client-cookie] structure.
|
||||
}
|
||||
|
||||
@defproc[(request-cookies [req request?])
|
||||
|
@ -364,7 +365,7 @@ An implementation of HTTP Basic Authentication.
|
|||
Returns a pair of the username and password from the authentication
|
||||
header in @racket[req] if they are present, or @racket[#f].
|
||||
}
|
||||
|
||||
|
||||
Example:
|
||||
@racketmod[
|
||||
web-server/insta
|
||||
|
@ -408,32 +409,36 @@ An implementation of HTTP Digest Authentication.
|
|||
(or/c false/c (listof (cons/c symbol? string?)))]{
|
||||
Returns the Digest credentials from @racket[req] (if they appear) as an association list.
|
||||
}
|
||||
|
||||
|
||||
@defthing[username*realm->password/c contract?]{
|
||||
Used to look up the password for a user is a realm.
|
||||
|
||||
Equivalent to @racket[(string? string? . -> . string?)].
|
||||
Used to look up the password for a user is a realm.
|
||||
|
||||
Equivalent to @racket[(string? string? . -> . string?)].
|
||||
}
|
||||
|
||||
@defthing[username*realm->digest-HA1/c contract?]{
|
||||
Used to compute the user's secret hash.
|
||||
|
||||
|
||||
Equivalent to @racket[(string? string? . -> . bytes?)].
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@defproc[(password->digest-HA1 [lookup-password username*realm->password/c])
|
||||
username*realm->digest-HA1/c]{
|
||||
Uses @racket[lookup-password] to find the password, then computes the secret hash of it.
|
||||
}
|
||||
|
||||
Uses @racket[lookup-password] to find the password, then computes the
|
||||
secret hash of it.
|
||||
}
|
||||
|
||||
@defproc[(make-check-digest-credentials [lookup-HA1 username*realm->digest-HA1/c])
|
||||
(string? (listof (cons/c symbol? string?)) . -> . boolean?)]{
|
||||
Constructs a function that checks whether particular Digest credentials (the second argument of the returned function)
|
||||
are correct given the HTTP method provided as the first argument and the secret hash computed by @racket[lookup-HA1].
|
||||
|
||||
This is will result in an exception if the Digest credentials are missing portions.
|
||||
}
|
||||
|
||||
Constructs a function that checks whether particular Digest credentials
|
||||
(the second argument of the returned function) are correct given the
|
||||
HTTP method provided as the first argument and the secret hash computed
|
||||
by @racket[lookup-HA1].
|
||||
|
||||
This is will result in an exception if the Digest credentials are
|
||||
missing portions.
|
||||
}
|
||||
|
||||
Example:
|
||||
@racketmod[
|
||||
web-server/insta
|
||||
|
@ -471,7 +476,7 @@ web-server/insta
|
|||
xml))
|
||||
|
||||
@defmodule[web-server/http/xexpr]{
|
||||
|
||||
|
||||
@defproc[(response/xexpr [xexpr xexpr/c]
|
||||
[#:code code number? 200]
|
||||
[#:message message bytes? #"Okay"]
|
||||
|
|
|
@ -45,9 +45,9 @@ An example @racket['stateless] servlet module:
|
|||
(provide interface-version stuffer start)
|
||||
(define interface-version 'stateless)
|
||||
(define stuffer
|
||||
(stuffer-chain
|
||||
serialize-stuffer
|
||||
(md5-stuffer (build-path (find-system-path 'home-dir) ".urls"))))
|
||||
(stuffer-chain
|
||||
serialize-stuffer
|
||||
(md5-stuffer (build-path (find-system-path 'home-dir) ".urls"))))
|
||||
(define (start req)
|
||||
(response/xexpr
|
||||
`(html (body (h2 "Look ma, no state!")))))
|
||||
|
|
|
@ -68,7 +68,7 @@ the users and implementers of managers.
|
|||
This exception should be thrown by a manager when a continuation is
|
||||
looked up that does not exist.
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@; ------------------------------------------------------------
|
||||
|
|
|
@ -21,10 +21,11 @@ of @racketmodname[web-server/dispatchers/dispatch-servlets].
|
|||
|
||||
@defproc[(make-make-servlet-namespace (#:to-be-copied-module-specs to-be-copied-module-specs (listof module-path?)))
|
||||
make-servlet-namespace/c]{
|
||||
This function creates a function that when called will construct a new @racket[namespace] that
|
||||
has all the modules from @racket[to-be-copied-module-specs] and @racket[additional-specs], as well
|
||||
as @racket[racket] and @racket[mred], provided they are already attached
|
||||
to the @racket[(current-namespace)] of the call-site.
|
||||
This function creates a function that when called will construct a new
|
||||
@racket[namespace] that has all the modules from
|
||||
@racket[to-be-copied-module-specs] and @racket[additional-specs], as
|
||||
well as @racket[racket] and @racket[mred], provided they are already
|
||||
attached to the @racket[(current-namespace)] of the call-site.
|
||||
|
||||
Example:
|
||||
@racketblock[
|
||||
|
@ -32,19 +33,22 @@ Example:
|
|||
#:to-be-copied-module-specs `((lib "database.rkt" "my-module")))
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@section{Why this is useful}
|
||||
|
||||
A different namespace is needed for each servlet, so that if servlet A and servlet B both use
|
||||
a stateful module C, they will be isolated from one another. We see the @web-server as
|
||||
an operating system for servlets, so we inherit the isolation requirement on operating systems.
|
||||
A different namespace is needed for each servlet, so that if servlet A
|
||||
and servlet B both use a stateful module C, they will be isolated from
|
||||
one another. We see the @web-server as an operating system for servlets,
|
||||
so we inherit the isolation requirement on operating systems.
|
||||
|
||||
However, there are some modules which must be shared. If they were not, then structures cannot
|
||||
be passed from the @web-server to the servlets, because Racket's structures are generative.
|
||||
However, there are some modules which must be shared. If they were not,
|
||||
then structures cannot be passed from the @web-server to the servlets,
|
||||
because Racket's structures are generative.
|
||||
|
||||
Since, on occasion, a user will actually wanted servlets A and B to interact through module C.
|
||||
A custom @racket[make-servlet-namespace] can be created, through this procedure, that attaches
|
||||
module C to all servlet namespaces. Through other means (see @secref["dispatchers"]) different sets
|
||||
of servlets can share different sets of modules.
|
||||
Since, on occasion, a user will actually wanted servlets A and B to
|
||||
interact through module C. A custom @racket[make-servlet-namespace] can
|
||||
be created, through this procedure, that attaches module C to all
|
||||
servlet namespaces. Through other means (see @secref["dispatchers"])
|
||||
different sets of servlets can share different sets of modules.
|
||||
|
|
|
@ -9,18 +9,23 @@
|
|||
|
||||
@defmodule[web-server/lang/native]{
|
||||
|
||||
It is sometimes inconvenient to use @racket[serial->native] and @racket[native->serial] throughout your program.
|
||||
This module provides a macro for creating wrappers.
|
||||
It is sometimes inconvenient to use @racket[serial->native] and
|
||||
@racket[native->serial] throughout your program. This module provides a
|
||||
macro for creating wrappers.
|
||||
|
||||
@defform[#:literals (ho)
|
||||
(define-native (native arg-spec ...) original)
|
||||
#:contracts ([arg-spec ho] [arg-spec _])]{
|
||||
Builds an interface around @racket[original] named @racket[native] such
|
||||
that calls to @racket[native] are wrapped in @racket[serial->native]
|
||||
and all arguments marked with @racket[ho] in @racket[arg-spec] are
|
||||
assumed to procedures and are wrapped in @racket[native->serial].
|
||||
|
||||
@defform[#:literals (ho) (define-native (native arg-spec ...) original) #:contracts ([arg-spec ho] [arg-spec _])]{
|
||||
Builds an interface around @racket[original] named @racket[native] such that calls to @racket[native] are wrapped in @racket[serial->native]
|
||||
and all arguments marked with @racket[ho] in @racket[arg-spec] are assumed to procedures and are wrapped in @racket[native->serial].
|
||||
|
||||
For example,
|
||||
@racketblock[
|
||||
(define-native (build-list/native _ ho) build-list)
|
||||
]
|
||||
|
||||
|
||||
is equivalent to
|
||||
@racketblock[
|
||||
(define (build-list/native fst snd)
|
||||
|
@ -32,5 +37,5 @@ This module provides a macro for creating wrappers.
|
|||
(apply snd args))))))
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user