use `scribble/examples' for the Reference

Port `examples`, `interactions`, etc., to use the new `examples`
form of `scribble/examples`. The main intended effect is to ensure
that errors are produced by examples only as specifically
indicated.
This commit is contained in:
Matthew Flatt 2015-12-11 10:06:13 -07:00
parent e45e5712de
commit 4354ce45d8
51 changed files with 898 additions and 830 deletions

View File

@ -2,7 +2,7 @@
@(require scribblings/reference/mz (for-label compatibility/package)) @(require scribblings/reference/mz (for-label compatibility/package))
@(define pack-eval (make-base-eval)) @(define pack-eval (make-base-eval))
@interaction-eval[#:eval pack-eval (require compatibility/package)] @examples[#:hidden #:eval pack-eval (require compatibility/package)]
@title[#:tag "compatibility-package"]{Limiting Scope: @racket[define-package], @racket[open-package], ...} @title[#:tag "compatibility-package"]{Limiting Scope: @racket[define-package], @racket[open-package], ...}
@ -61,11 +61,11 @@ is the exported one.
(define-package presents (doll) (define-package presents (doll)
(define doll "Molly Coddle") (define doll "Molly Coddle")
(define robot "Destructo")) (define robot "Destructo"))
doll (eval:error doll)
robot (eval:error robot)
(open-package presents) (open-package presents)
doll doll
robot (eval:error robot)
(define-package big-russian-doll (middle-russian-doll) (define-package big-russian-doll (middle-russian-doll)
(define-package middle-russian-doll (little-russian-doll) (define-package middle-russian-doll (little-russian-doll)
(define little-russian-doll "Anastasia"))) (define little-russian-doll "Anastasia")))
@ -95,7 +95,7 @@ the defined bindings remain hidden outside the
(package-begin (package-begin
(define secret "mimi") (define secret "mimi")
(list secret)) (list secret))
secret (eval:error secret)
]} ]}
@deftogether[( @deftogether[(

View File

@ -6,7 +6,7 @@
"base" "base"
"net-lib" "net-lib"
"sandbox-lib" "sandbox-lib"
"scribble-lib" ["scribble-lib" #:version "1.14"]
"racket-index")) "racket-index"))
(define build-deps '("rackunit-doc" (define build-deps '("rackunit-doc"
"compatibility" "compatibility"

View File

@ -70,27 +70,27 @@ synchronization} when @racket[(async-channel-put ach v)] would return
a value (i.e., when the channel holds fewer values already than its a value (i.e., when the channel holds fewer values already than its
limit); @resultItself{asychronous channel-put event}.} limit); @resultItself{asychronous channel-put event}.}
@defexamples[#:eval (async-eval) @examples[#:eval (async-eval) #:once
(define (server input-channel output-channel) (eval:no-prompt
(thread (lambda () (define (server input-channel output-channel)
(define (get) (thread (lambda ()
(async-channel-get input-channel)) (define (get)
(define (put x) (async-channel-get input-channel))
(async-channel-put output-channel x)) (define (put x)
(define (do-large-computation) (async-channel-put output-channel x))
(sqrt 9)) (define (do-large-computation)
(let loop ([data (get)]) (sqrt 9))
(case data (let loop ([data (get)])
[(quit) (void)] (case data
[(add) (begin [(quit) (void)]
(put (+ 1 (get))) [(add) (begin
(loop (get)))] (put (+ 1 (get)))
[(long) (begin (loop (get)))]
(put (do-large-computation)) [(long) (begin
(loop (get)))]))))) (put (do-large-computation))
(loop (get)))])))))
(define to-server (make-async-channel)) (define to-server (make-async-channel))
(define from-server (make-async-channel)) (define from-server (make-async-channel)))
(server to-server from-server) (server to-server from-server)

View File

@ -1,5 +1,5 @@
#lang scribble/doc #lang scribble/doc
@(require "mz.rkt" scribble/eval (for-label racket/block)) @(require "mz.rkt" (for-label racket/block))
@(define ev (make-base-eval)) @(define ev (make-base-eval))
@(ev '(require racket/block)) @(ev '(require racket/block))

View File

@ -643,7 +643,7 @@ normally identified by @racket[""]). See also
@section{Additional Byte String Functions} @section{Additional Byte String Functions}
@note-lib[racket/bytes] @note-lib[racket/bytes]
@(define string-eval (make-base-eval)) @(define string-eval (make-base-eval))
@(interaction-eval #:eval string-eval (require racket/bytes racket/list)) @@examples[#:hidden #:eval string-eval (require racket/bytes racket/list)]
@defproc[(bytes-append* [str bytes?] ... [strs (listof bytes?)]) bytes?]{ @defproc[(bytes-append* [str bytes?] ... [strs (listof bytes?)]) bytes?]{
@; Note: this is exactly the same description as the one for append* @; Note: this is exactly the same description as the one for append*

View File

@ -924,11 +924,12 @@ procedure.
(lambda (n) (* n 2)) (lambda (n) (* n 2))
(lambda (n) (+ n 1)))) (lambda (n) (+ n 1))))
(call-with-continuation-prompt (eval:error
(lambda () (call-with-continuation-prompt
(abort-current-continuation bad-chaperone 5)) (lambda ()
bad-chaperone (abort-current-continuation bad-chaperone 5))
(lambda (n) n)) bad-chaperone
(lambda (n) n)))
(define good-chaperone (define good-chaperone
(chaperone-prompt-tag (chaperone-prompt-tag
@ -966,10 +967,11 @@ given.
(lambda (l) (map char-upcase l)) (lambda (l) (map char-upcase l))
string->list)) string->list))
(with-continuation-mark bad-chaperone "timballo" (eval:error
(continuation-mark-set-first (with-continuation-mark bad-chaperone "timballo"
(current-continuation-marks) (continuation-mark-set-first
bad-chaperone)) (current-continuation-marks)
bad-chaperone)))
(define (checker s) (define (checker s)
(if (> (string-length s) 5) (if (> (string-length s) 5)

View File

@ -71,11 +71,10 @@
) )
@(interaction-eval #:eval class-eval (require racket/class racket/contract)) @examples[#:hidden #:eval class-eval
@(interaction-eval (require racket/class racket/contract)]
#:eval class-ctc-eval @examples[#:hidden #:eval class-ctc-eval
(require racket/class racket/contract)) (require racket/class racket/contract)]
@title[#:tag "mzlib:class" #:style 'toc]{Classes and Objects} @title[#:tag "mzlib:class" #:style 'toc]{Classes and Objects}
@ -196,8 +195,9 @@ is the most specific requirement from its superinterfaces. If the
superinterfaces specify inconsistent derivation requirements, the superinterfaces specify inconsistent derivation requirements, the
@exnraise[exn:fail:object]. @exnraise[exn:fail:object].
@defexamples[ @examples[
#:eval class-ctc-eval #:eval class-ctc-eval
#:no-prompt
(define file-interface<%> (define file-interface<%>
(interface () open close read-byte write-byte)) (interface () open close read-byte write-byte))
(define directory-interface<%> (define directory-interface<%>
@ -226,8 +226,9 @@ extended to produce the internal structure type for instances of the
class (so that no information about fields is accessible to the class (so that no information about fields is accessible to the
structure type property's guard, if any). structure type property's guard, if any).
@defexamples[ @examples[
#:eval class-eval #:eval class-eval
#:no-prompt
(define i<%> (interface* () ([prop:custom-write (define i<%> (interface* () ([prop:custom-write
(lambda (obj port mode) (void))]) (lambda (obj port mode) (void))])
method1 method2 method3)) method1 method2 method3))
@ -387,8 +388,9 @@ calling subclass augmentations of methods (see
Like @racket[class*], but omits the @racket[_interface-expr]s, for the case that none are needed. Like @racket[class*], but omits the @racket[_interface-expr]s, for the case that none are needed.
@defexamples[ @examples[
#:eval class-eval #:eval class-eval
#:no-prompt
(define book-class% (define book-class%
(class object% (class object%
(field (pages 5)) (field (pages 5))
@ -404,15 +406,16 @@ to the current object (i.e., the object being initialized or whose
method was called). Use outside the body of a @racket[class*] form is method was called). Use outside the body of a @racket[class*] form is
a syntax error. a syntax error.
@defexamples[ @examples[
#:eval class-eval #:eval class-eval
(define (describe obj) (eval:no-prompt
(printf "Hello ~a\n" obj)) (define (describe obj)
(define table% (printf "Hello ~a\n" obj))
(class object% (define table%
(define/public (describe-self) (class object%
(describe this)) (define/public (describe-self)
(super-new))) (describe this))
(super-new))))
(send (new table%) describe-self) (send (new table%) describe-self)
]} ]}
@ -423,21 +426,22 @@ of the current object (i.e., the object being initialized or whose
method was called). Use outside the body of a @racket[class*] form is method was called). Use outside the body of a @racket[class*] form is
a syntax error. a syntax error.
@defexamples[ @examples[
#:eval class-eval #:eval class-eval
(define account% (eval:no-prompt
(class object% (define account%
(super-new) (class object%
(init-field balance) (super-new)
(define/public (add n) (init-field balance)
(new this% [balance (+ n balance)])))) (define/public (add n)
(define savings% (new this% [balance (+ n balance)]))))
(class account% (define savings%
(super-new) (class account%
(inherit-field balance) (super-new)
(define interest 0.04) (inherit-field balance)
(define/public (add-interest) (define interest 0.04)
(send this add (* interest balance))))) (define/public (add-interest)
(send this add (* interest balance))))))
(let* ([acct (new savings% [balance 500])] (let* ([acct (new savings% [balance 500])]
[acct (send acct add 500)] [acct (send acct add 500)]
[acct (send acct add-interest)]) [acct (send acct add-interest)])
@ -447,7 +451,7 @@ a syntax error.
@defclassforms[ @defclassforms[
[(inspect inspector-expr) ()] [(inspect inspector-expr) ()]
[(init init-decl ...) ("clinitvars") [(init init-decl ...) ("clinitvars")
@defexamples[#:eval class-eval @examples[#:eval class-eval
(class object% (class object%
(super-new) (super-new)
(init turnip (init turnip
@ -455,7 +459,7 @@ a syntax error.
[carrot 'good] [carrot 'good]
[(internal-rutabaga rutabaga) 'okay]))]] [(internal-rutabaga rutabaga) 'okay]))]]
[(init-field init-decl ...) ("clinitvars" "clfields") [(init-field init-decl ...) ("clinitvars" "clfields")
@defexamples[#:eval class-eval @examples[#:eval class-eval
(class object% (class object%
(super-new) (super-new)
(init-field turkey (init-field turkey
@ -463,181 +467,202 @@ a syntax error.
[chicken 7] [chicken 7]
[(internal-emu emu) 13]))]] [(internal-emu emu) 13]))]]
[(field field-decl ...) ("clfields") [(field field-decl ...) ("clfields")
@defexamples[#:eval class-eval @examples[#:eval class-eval
(class object% (class object%
(super-new) (super-new)
(field [minestrone 'ready] (field [minestrone 'ready]
[(internal-coq-au-vin coq-au-vin) 'stewing]))]] [(internal-coq-au-vin coq-au-vin) 'stewing]))]]
[(inherit-field maybe-renamed ...) ("clfields") [(inherit-field maybe-renamed ...) ("clfields")
@defexamples[#:eval class-eval @examples[#:eval class-eval
(define cookbook% (eval:no-prompt
(class object% (define cookbook%
(super-new) (class object%
(field [recipes '(caldo-verde oyakodon eggs-benedict)] (super-new)
[pages 389]))) (field [recipes '(caldo-verde oyakodon eggs-benedict)]
[pages 389]))))
(class cookbook% (class cookbook%
(super-new) (super-new)
(inherit-field recipes (inherit-field recipes
[internal-pages pages]))]] [internal-pages pages]))]]
[* ((init-rest id) (init-rest)) ("clinitvars") [* ((init-rest id) (init-rest)) ("clinitvars")
@defexamples[#:eval class-eval @examples[#:eval class-eval
(define fruit-basket% (eval:no-prompt
(class object% (define fruit-basket%
(super-new)
(init-rest fruits)
(displayln fruits)))
(make-object fruit-basket% 'kiwi 'lychee 'melon)]]
[(public maybe-renamed ...) ("clmethoddefs")
@defexamples[#:eval class-eval
(define jumper%
(class object% (class object%
(super-new) (super-new)
(define (skip) 'skip) (init-rest fruits)
(define (hop) 'hop) (displayln fruits))))
(public skip [hop jump]))) (make-object fruit-basket% 'kiwi 'lychee 'melon)]]
[(public maybe-renamed ...) ("clmethoddefs")
@examples[#:eval class-eval
(eval:no-prompt
(define jumper%
(class object%
(super-new)
(define (skip) 'skip)
(define (hop) 'hop)
(public skip [hop jump]))))
(send (new jumper%) skip) (send (new jumper%) skip)
(send (new jumper%) jump)]] (send (new jumper%) jump)]]
[(pubment maybe-renamed ...) ("clmethoddefs") [(pubment maybe-renamed ...) ("clmethoddefs")
@defexamples[#:eval class-eval @examples[#:eval class-eval
(define runner% (eval:no-prompt
(class object% (define runner%
(super-new) (class object%
(define (run) 'run) (super-new)
(define (trot) 'trot) (define (run) 'run)
(pubment run [trot jog]))) (define (trot) 'trot)
(pubment run [trot jog]))))
(send (new runner%) run) (send (new runner%) run)
(send (new runner%) jog)]] (send (new runner%) jog)]]
[(public-final maybe-renamed ...) ("clmethoddefs") [(public-final maybe-renamed ...) ("clmethoddefs")
@defexamples[#:eval class-eval @examples[#:eval class-eval
(define point% (eval:no-prompt
(class object% (define point%
(super-new) (class object%
(init-field [x 0] [y 0]) (super-new)
(define (get-x) x) (init-field [x 0] [y 0])
(define (do-get-y) y) (define (get-x) x)
(public-final get-x [do-get-y get-y]))) (define (do-get-y) y)
(public-final get-x [do-get-y get-y]))))
(send (new point% [x 1] [y 3]) get-y) (send (new point% [x 1] [y 3]) get-y)
(class point% (eval:error
(super-new) (class point%
(define (get-x) 3.14) (super-new)
(override get-x))]] (define (get-x) 3.14)
(override get-x)))]]
[(override maybe-renamed ...) ("clmethoddefs") [(override maybe-renamed ...) ("clmethoddefs")
@defexamples[#:eval class-eval @examples[#:eval class-eval
(define sheep% (eval:no-prompt
(class object% (define sheep%
(super-new) (class object%
(define/public (bleat) (super-new)
(displayln "baaaaaaaaah")))) (define/public (bleat)
(define confused-sheep% (displayln "baaaaaaaaah")))))
(class sheep% (eval:no-prompt
(super-new) (define confused-sheep%
(define (bleat) (class sheep%
(super bleat) (super-new)
(displayln "???")) (define (bleat)
(override bleat))) (super bleat)
(displayln "???"))
(override bleat))))
(send (new sheep%) bleat) (send (new sheep%) bleat)
(send (new confused-sheep%) bleat)]] (send (new confused-sheep%) bleat)]]
[(overment maybe-renamed ...) ("clmethoddefs") [(overment maybe-renamed ...) ("clmethoddefs")
@defexamples[#:eval class-eval @examples[#:eval class-eval
(define turkey% (eval:no-prompt
(class object% (define turkey%
(super-new) (class object%
(define/public (gobble) (super-new)
(displayln "gobble gobble")))) (define/public (gobble)
(define extra-turkey% (displayln "gobble gobble")))))
(class turkey% (eval:no-prompt
(super-new) (define extra-turkey%
(define (gobble) (class turkey%
(super gobble) (super-new)
(displayln "gobble gobble gobble") (define (gobble)
(inner (void) gobble)) (super gobble)
(overment gobble))) (displayln "gobble gobble gobble")
(define cyborg-turkey% (inner (void) gobble))
(class extra-turkey% (overment gobble))))
(super-new) (eval:no-prompt
(define/augment (gobble) (define cyborg-turkey%
(displayln "110011111011111100010110001011011001100101")))) (class extra-turkey%
(super-new)
(define/augment (gobble)
(displayln "110011111011111100010110001011011001100101")))))
(send (new extra-turkey%) gobble) (send (new extra-turkey%) gobble)
(send (new cyborg-turkey%) gobble)]] (send (new cyborg-turkey%) gobble)]]
[(override-final maybe-renamed ...) ("clmethoddefs") [(override-final maybe-renamed ...) ("clmethoddefs")
@defexamples[#:eval class-eval @examples[#:eval class-eval
(define meeper% (eval:no-prompt
(class object% (define meeper%
(super-new) (class object%
(define/public (meep) (super-new)
(displayln "meep")))) (define/public (meep)
(define final-meeper% (displayln "meep")))))
(class meeper% (eval:no-prompt
(super-new) (define final-meeper%
(define (meep) (class meeper%
(super meep) (super-new)
(displayln "This meeping ends with me")) (define (meep)
(override-final meep))) (super meep)
(displayln "This meeping ends with me"))
(override-final meep))))
(send (new meeper%) meep) (send (new meeper%) meep)
(send (new final-meeper%) meep)]] (send (new final-meeper%) meep)]]
[(augment maybe-renamed ...) ("clmethoddefs") [(augment maybe-renamed ...) ("clmethoddefs")
@defexamples[#:eval class-eval @examples[#:eval class-eval
(define buzzer% (eval:no-prompt
(class object% (define buzzer%
(super-new) (class object%
(define/pubment (buzz) (super-new)
(displayln "bzzzt") (define/pubment (buzz)
(inner (void) buzz)))) (displayln "bzzzt")
(define loud-buzzer% (inner (void) buzz)))))
(class buzzer% (eval:no-prompt
(super-new) (define loud-buzzer%
(define (buzz) (class buzzer%
(displayln "BZZZZZZZZZT")) (super-new)
(augment buzz))) (define (buzz)
(displayln "BZZZZZZZZZT"))
(augment buzz))))
(send (new buzzer%) buzz) (send (new buzzer%) buzz)
(send (new loud-buzzer%) buzz)]] (send (new loud-buzzer%) buzz)]]
[(augride maybe-renamed ...) ("clmethoddefs")] [(augride maybe-renamed ...) ("clmethoddefs")]
[(augment-final maybe-renamed ...) ("clmethoddefs")] [(augment-final maybe-renamed ...) ("clmethoddefs")]
[(private id ...) ("clmethoddefs") [(private id ...) ("clmethoddefs")
@defexamples[#:eval class-eval @examples[#:eval class-eval
(define light% (eval:no-prompt
(class object% (define light%
(super-new) (class object%
(define on? #t) (super-new)
(define (toggle) (set! on? (not on?))) (define on? #t)
(private toggle) (define (toggle) (set! on? (not on?)))
(define (flick) (toggle)) (private toggle)
(public flick))) (define (flick) (toggle))
(send (new light%) toggle) (public flick))))
(eval:error (send (new light%) toggle))
(send (new light%) flick)]] (send (new light%) flick)]]
[(abstract id ...) ("clmethoddefs") [(abstract id ...) ("clmethoddefs")
@defexamples[#:eval class-eval @examples[#:eval class-eval
(define train% (eval:no-prompt
(class object% (define train%
(super-new) (class object%
(abstract get-speed) (super-new)
(init-field [position 0]) (abstract get-speed)
(define/public (move) (init-field [position 0])
(new this% [position (+ position (get-speed))])))) (define/public (move)
(define acela% (new this% [position (+ position (get-speed))])))))
(class train% (eval:no-prompt
(super-new) (define acela%
(define/override (get-speed) 241))) (class train%
(define talgo-350% (super-new)
(class train% (define/override (get-speed) 241))))
(super-new) (eval:no-prompt
(define/override (get-speed) 330))) (define talgo-350%
(new train%) (class train%
(super-new)
(define/override (get-speed) 330))))
(eval:error (new train%))
(send (new acela%) move)]] (send (new acela%) move)]]
[(inherit maybe-renamed ...) ("classinherit") [(inherit maybe-renamed ...) ("classinherit")
@defexamples[#:eval class-eval @examples[#:eval class-eval
(define alarm% (eval:no-prompt
(class object% (define alarm%
(super-new) (class object%
(define/public (alarm) (super-new)
(displayln "beeeeeeeep")))) (define/public (alarm)
(define car-alarm% (displayln "beeeeeeeep")))))
(class alarm% (eval:no-prompt
(super-new) (define car-alarm%
(init-field proximity) (class alarm%
(inherit alarm) (super-new)
(when (< proximity 10) (init-field proximity)
(alarm)))) (inherit alarm)
(when (< proximity 10)
(alarm)))))
(new car-alarm% [proximity 5])]] (new car-alarm% [proximity 5])]]
[(inherit/super maybe-renamed ...) ("classinherit")] [(inherit/super maybe-renamed ...) ("classinherit")]
[(inherit/inner maybe-renamed ...) ("classinherit")] [(inherit/inner maybe-renamed ...) ("classinherit")]
@ -1067,21 +1092,22 @@ hidden name (except as a top-level definition). The
@racket[interface->method-names] procedure does not expose hidden @racket[interface->method-names] procedure does not expose hidden
names. names.
@defexamples[ @examples[
#:eval class-eval #:eval class-eval
(define-values (r o) (eval:no-prompt
(let () (define-values (r o)
(define-local-member-name m) (let ()
(define c% (class object% (define-local-member-name m)
(define/public (m) 10) (define c% (class object%
(super-new))) (define/public (m) 10)
(define o (new c%)) (super-new)))
(define o (new c%))
(values (send o m) (values (send o m)
o))) o))))
r r
(send o m) (eval:error (send o m))
]} ]}
@ -1121,28 +1147,27 @@ Produces an integer hash code consistent with
@racket[member-name-key=?] comparisons, analogous to @racket[member-name-key=?] comparisons, analogous to
@racket[equal-hash-code].} @racket[equal-hash-code].}
@defexamples[ @examples[
#:eval class-eval #:eval class-eval
(define (make-c% key) (eval:no-prompt
(define-member-name m key) (define (make-c% key)
(class object% (define-member-name m key)
(define/public (m) 10) (class object%
(super-new))) (define/public (m) 10)
(super-new))))
(send (new (make-c% (member-name-key m))) m) (send (new (make-c% (member-name-key m))) m)
(send (new (make-c% (member-name-key p))) m) (eval:error (send (new (make-c% (member-name-key p))) m))
(send (new (make-c% (member-name-key p))) p) (send (new (make-c% (member-name-key p))) p)
]
@defs+int[ (eval:no-prompt
#:eval class-eval (define (fresh-c%)
[(define (fresh-c%)
(let ([key (generate-member-key)]) (let ([key (generate-member-key)])
(values (make-c% key) key))) (values (make-c% key) key)))
(define-values (fc% key) (fresh-c%))] (define-values (fc% key) (fresh-c%)))
(send (new fc%) m) (eval:error (send (new fc%) m))
(let () (let ()
(define-member-name p key) (define-member-name p key)
(send (new fc%) p)) (send (new fc%) p))
@ -1352,15 +1377,16 @@ the last method call, which is expected to be an object. Each
This is the functional analogue of @racket[send*]. This is the functional analogue of @racket[send*].
@defexamples[#:eval class-eval @examples[#:eval class-eval
(define point% (eval:no-prompt
(class object% (define point%
(super-new) (class object%
(init-field [x 0] [y 0]) (super-new)
(define/public (move-x dx) (init-field [x 0] [y 0])
(new this% [x (+ x dx)])) (define/public (move-x dx)
(define/public (move-y dy) (new this% [x (+ x dx)]))
(new this% [y (+ y dy)])))) (define/public (move-y dy)
(new this% [y (+ y dy)])))))
(send+ (new point%) (send+ (new point%)
(move-x 5) (move-x 5)
@ -1802,21 +1828,21 @@ The external contracts are as follows:
If only the field name is present, this is equivalent to insisting only If only the field name is present, this is equivalent to insisting only
that the method is present in the class. that the method is present in the class.
@defexamples[#:eval @examples[#:eval class-eval
class-eval (eval:no-prompt
(define woody% (define woody%
(class object% (class object%
(define/public (draw who) (define/public (draw who)
(format "reach for the sky, ~a" who)) (format "reach for the sky, ~a" who))
(super-new))) (super-new)))
(define/contract woody+c% (define/contract woody+c%
(class/c [draw (->m symbol? string?)]) (class/c [draw (->m symbol? string?)])
woody%) woody%))
(send (new woody%) draw #f) (send (new woody%) draw #f)
(send (new woody+c%) draw 'zurg) (send (new woody+c%) draw 'zurg)
(send (new woody+c%) draw #f)] (eval:error (send (new woody+c%) draw #f))]
} }
@item{An external field contract, tagged with @racket[field], describes the @item{An external field contract, tagged with @racket[field], describes the
behavior of the value contained in that field when accessed from outside behavior of the value contained in that field when accessed from outside
@ -1827,28 +1853,29 @@ The external contracts are as follows:
If only the field name is present, this is equivalent to using the If only the field name is present, this is equivalent to using the
contract @racket[any/c] (but it is checked more efficiently). contract @racket[any/c] (but it is checked more efficiently).
@defexamples[#:eval @examples[#:eval class-eval
class-eval (eval:no-prompt
(define woody/hat% (define woody/hat%
(class woody% (class woody%
(field [hat-location 'uninitialized]) (field [hat-location 'uninitialized])
(define/public (lose-hat) (set! hat-location 'lost)) (define/public (lose-hat) (set! hat-location 'lost))
(define/public (find-hat) (set! hat-location 'on-head)) (define/public (find-hat) (set! hat-location 'on-head))
(super-new))) (super-new)))
(define/contract woody/hat+c% (define/contract woody/hat+c%
(class/c [draw (->m symbol? string?)] (class/c [draw (->m symbol? string?)]
[lose-hat (->m void?)] [lose-hat (->m void?)]
[find-hat (->m void?)] [find-hat (->m void?)]
(field [hat-location (or/c 'on-head 'lost)])) (field [hat-location (or/c 'on-head 'lost)]))
woody/hat%) woody/hat%))
(get-field hat-location (new woody/hat%)) (get-field hat-location (new woody/hat%))
(let ([woody (new woody/hat+c%)]) (let ([woody (new woody/hat+c%)])
(send woody lose-hat) (send woody lose-hat)
(get-field hat-location woody)) (get-field hat-location woody))
(get-field hat-location (new woody/hat+c%)) (eval:error (get-field hat-location (new woody/hat+c%)))
(let ([woody (new woody/hat+c%)]) (eval:error
(set-field! hat-location woody 'under-the-dresser))] (let ([woody (new woody/hat+c%)])
(set-field! hat-location woody 'under-the-dresser)))]
} }
@item{An initialization argument contract, tagged with @racket[init], @item{An initialization argument contract, tagged with @racket[init],
@ -1861,28 +1888,29 @@ The external contracts are as follows:
If only the initialization argument name is present, this is equivalent to using the If only the initialization argument name is present, this is equivalent to using the
contract @racket[any/c] (but it is checked more efficiently). contract @racket[any/c] (but it is checked more efficiently).
@defexamples[#:eval @examples[#:eval class-eval
class-eval (eval:no-prompt
(define woody/init-hat% (define woody/init-hat%
(class woody% (class woody%
(init init-hat-location) (init init-hat-location)
(field [hat-location init-hat-location]) (field [hat-location init-hat-location])
(define/public (lose-hat) (set! hat-location 'lost)) (define/public (lose-hat) (set! hat-location 'lost))
(define/public (find-hat) (set! hat-location 'on-head)) (define/public (find-hat) (set! hat-location 'on-head))
(super-new))) (super-new)))
(define/contract woody/init-hat+c% (define/contract woody/init-hat+c%
(class/c [draw (->m symbol? string?)] (class/c [draw (->m symbol? string?)]
[lose-hat (->m void?)] [lose-hat (->m void?)]
[find-hat (->m void?)] [find-hat (->m void?)]
(init [init-hat-location (or/c 'on-head 'lost)]) (init [init-hat-location (or/c 'on-head 'lost)])
(field [hat-location (or/c 'on-head 'lost)])) (field [hat-location (or/c 'on-head 'lost)]))
woody/init-hat%) woody/init-hat%))
(get-field hat-location (get-field hat-location
(new woody/init-hat+c% (new woody/init-hat+c%
[init-hat-location 'lost])) [init-hat-location 'lost]))
(get-field hat-location (eval:error
(new woody/init-hat+c% (get-field hat-location
[init-hat-location 'slinkys-mouth]))] (new woody/init-hat+c%
[init-hat-location 'slinkys-mouth])))]
} }
@item{The contracts listed in an @racket[init-field] section are @item{The contracts listed in an @racket[init-field] section are
@ -1906,18 +1934,19 @@ As with the external contracts, when a method or field name is specified
contracted class's method implementation is no longer the entry point contracted class's method implementation is no longer the entry point
for dynamic dispatch. for dynamic dispatch.
@defexamples[#:eval @examples[#:eval class-eval
class-eval
(new (class woody+c% (new (class woody+c%
(inherit draw) (inherit draw)
(super-new) (super-new)
(printf "woody sez: “~a”\n" (draw "evil dr porkchop")))) (printf "woody sez: “~a”\n" (draw "evil dr porkchop"))))
(define/contract woody+c-inherit% (eval:no-prompt
(class/c (inherit [draw (->m symbol? string?)])) (define/contract woody+c-inherit%
woody+c%) (class/c (inherit [draw (->m symbol? string?)]))
(new (class woody+c-inherit% woody+c%))
(inherit draw) (eval:error
(printf "woody sez: ~a\n" (draw "evil dr porkchop"))))] (new (class woody+c-inherit%
(inherit draw)
(printf "woody sez: ~a\n" (draw "evil dr porkchop")))))]
} }
@item{A method contract tagged with @racket[super] describes the behavior of @item{A method contract tagged with @racket[super] describes the behavior of
@ -1932,18 +1961,18 @@ As with the external contracts, when a method or field name is specified
contract the controls how the @racket[super] methods must contract the controls how the @racket[super] methods must
be invoked. be invoked.
@defexamples[#:eval @examples[#:eval class-eval
class-eval (eval:no-prompt
(define/contract woody2+c% (define/contract woody2+c%
(class/c (super [draw (->m symbol? string?)])) (class/c (super [draw (->m symbol? string?)]))
(class woody% (class woody%
(define/override draw (define/override draw
(case-lambda (case-lambda
[(a) (super draw a)] [(a) (super draw a)]
[(a b) (string-append (super draw a) [(a b) (string-append (super draw a)
" and " " and "
(super draw b))])) (super draw b))]))
(super-new))) (super-new))))
(send (new woody2+c%) draw 'evil-dr-porkchop 'zurg) (send (new woody2+c%) draw 'evil-dr-porkchop 'zurg)
(send (new woody2+c%) draw "evil dr porkchop" "zurg")] (send (new woody2+c%) draw "evil dr porkchop" "zurg")]
@ -1971,27 +2000,28 @@ As with the external contracts, when a method or field name is specified
add a contract to make sure that overriding @racket[draw] add a contract to make sure that overriding @racket[draw]
doesn't break @racket[draw2]. doesn't break @racket[draw2].
@defexamples[#:eval @examples[#:eval class-eval
class-eval (eval:no-prompt
(define/contract woody2+override/c% (define/contract woody2+override/c%
(class/c (override [draw (->m symbol? string?)])) (class/c (override [draw (->m symbol? string?)]))
(class woody+c% (class woody+c%
(inherit draw) (inherit draw)
(define/public (draw2 a b) (define/public (draw2 a b)
(string-append (draw a) (string-append (draw a)
" and " " and "
(draw b))) (draw b)))
(super-new))) (super-new)))
(define woody2+broken-draw (define woody2+broken-draw
(class woody2+override/c% (class woody2+override/c%
(define/override (draw x) (define/override (draw x)
'not-a-string) 'not-a-string)
(super-new))) (super-new))))
(send (new woody2+broken-draw) draw2 (eval:error
'evil-dr-porkchop (send (new woody2+broken-draw) draw2
'zurg)] 'evil-dr-porkchop
'zurg))]
} }
@ -2390,7 +2420,7 @@ A @racket[print] request is directed to @racket[custom-write].}
Returns @racket[#t] if @racket[v] is an object, @racket[#f] otherwise. Returns @racket[#t] if @racket[v] is an object, @racket[#f] otherwise.
@defexamples[#:eval class-eval @examples[#:eval class-eval
(object? (new object%)) (object? (new object%))
(object? object%) (object? object%)
(object? "clam chowder") (object? "clam chowder")
@ -2401,7 +2431,7 @@ Returns @racket[#t] if @racket[v] is an object, @racket[#f] otherwise.
Returns @racket[#t] if @racket[v] is a class, @racket[#f] otherwise. Returns @racket[#t] if @racket[v] is a class, @racket[#f] otherwise.
@defexamples[#:eval class-eval @examples[#:eval class-eval
(class? object%) (class? object%)
(class? (class object% (super-new))) (class? (class object% (super-new)))
(class? (new object%)) (class? (new object%))
@ -2413,7 +2443,7 @@ Returns @racket[#t] if @racket[v] is a class, @racket[#f] otherwise.
Returns @racket[#t] if @racket[v] is an interface, @racket[#f] otherwise. Returns @racket[#t] if @racket[v] is an interface, @racket[#f] otherwise.
@defexamples[#:eval class-eval @examples[#:eval class-eval
(interface? (interface () empty cons first rest)) (interface? (interface () empty cons first rest))
(interface? object%) (interface? object%)
(interface? "gazpacho") (interface? "gazpacho")
@ -2424,7 +2454,7 @@ Returns @racket[#t] if @racket[v] is an interface, @racket[#f] otherwise.
Returns @racket[#t] if @racket[v] is a @tech{generic}, @racket[#f] otherwise. Returns @racket[#t] if @racket[v] is a @tech{generic}, @racket[#f] otherwise.
@defexamples[#:eval class-eval @examples[#:eval class-eval
(define c% (define c%
(class object% (class object%
(super-new) (super-new)
@ -2448,7 +2478,7 @@ This procedure is similar in spirit to
@racket[eq?] but also works properly with contracts @racket[eq?] but also works properly with contracts
(and has a stronger guarantee). (and has a stronger guarantee).
@defexamples[#:eval class-ctc-eval @examples[#:eval class-ctc-eval
(define obj-1 (new object%)) (define obj-1 (new object%))
(define obj-2 (new object%)) (define obj-2 (new object%))
(define/contract obj-3 (object/c) obj-1) (define/contract obj-3 (object/c) obj-1)
@ -2468,7 +2498,7 @@ This procedure is similar in spirit to
Like @racket[object=?], but accepts @racket[#f] for either argument and Like @racket[object=?], but accepts @racket[#f] for either argument and
returns @racket[#t] if both arguments are @racket[#f]. returns @racket[#t] if both arguments are @racket[#f].
@defexamples[#:eval class-ctc-eval @examples[#:eval class-ctc-eval
(object-or-false=? #f (new object%)) (object-or-false=? #f (new object%))
(object-or-false=? (new object%) #f) (object-or-false=? (new object%) #f)
(object-or-false=? #f #f) (object-or-false=? #f #f)
@ -2482,7 +2512,7 @@ returns @racket[#t] if both arguments are @racket[#f].
Returns a vector representing @racket[object] that shows its Returns a vector representing @racket[object] that shows its
inspectable fields, analogous to @racket[struct->vector]. inspectable fields, analogous to @racket[struct->vector].
@defexamples[#:eval class-eval @examples[#:eval class-eval
(object->vector (new object%)) (object->vector (new object%))
(object->vector (new (class object% (object->vector (new (class object%
(super-new) (super-new)
@ -2494,7 +2524,7 @@ inspectable fields, analogous to @racket[struct->vector].
Returns the interface implicitly defined by @racket[class]. Returns the interface implicitly defined by @racket[class].
@defexamples[#:eval class-eval @examples[#:eval class-eval
(class->interface object%) (class->interface object%)
]} ]}
@ -2504,7 +2534,7 @@ Returns the interface implicitly defined by @racket[class].
Returns the interface implicitly defined by the class of Returns the interface implicitly defined by the class of
@racket[object]. @racket[object].
@defexamples[#:eval class-eval @examples[#:eval class-eval
(object-interface (new object%)) (object-interface (new object%))
]} ]}
@ -2515,7 +2545,7 @@ Returns @racket[#t] if @racket[v] is an instance of a class
@racket[type] or a class that implements an interface @racket[type], @racket[type] or a class that implements an interface @racket[type],
@racket[#f] otherwise. @racket[#f] otherwise.
@defexamples[#:eval class-eval @examples[#:eval class-eval
(define point<%> (interface () get-x get-y)) (define point<%> (interface () get-x get-y))
(define 2d-point% (define 2d-point%
(class* object% (point<%>) (class* object% (point<%>)
@ -2536,7 +2566,7 @@ Returns @racket[#t] if @racket[v] is an instance of a class
Returns @racket[#t] if @racket[v] is a class derived from (or equal Returns @racket[#t] if @racket[v] is a class derived from (or equal
to) @racket[cls], @racket[#f] otherwise. to) @racket[cls], @racket[#f] otherwise.
@defexamples[#:eval class-eval @examples[#:eval class-eval
(subclass? (class object% (super-new)) object%) (subclass? (class object% (super-new)) object%)
(subclass? object% (class object% (super-new))) (subclass? object% (class object% (super-new)))
(subclass? object% object%) (subclass? object% object%)
@ -2548,7 +2578,7 @@ to) @racket[cls], @racket[#f] otherwise.
Returns @racket[#t] if @racket[v] is a class that implements Returns @racket[#t] if @racket[v] is a class that implements
@racket[intf], @racket[#f] otherwise. @racket[intf], @racket[#f] otherwise.
@defexamples[#:eval class-eval @examples[#:eval class-eval
(define i<%> (interface () go)) (define i<%> (interface () go))
(define c% (define c%
(class* object% (i<%>) (class* object% (i<%>)
@ -2565,7 +2595,7 @@ Returns @racket[#t] if @racket[v] is a class that implements
Returns @racket[#t] if @racket[v] is an interface that extends Returns @racket[#t] if @racket[v] is an interface that extends
@racket[intf], @racket[#f] otherwise. @racket[intf], @racket[#f] otherwise.
@defexamples[#:eval class-eval @examples[#:eval class-eval
(define point<%> (interface () get-x get-y)) (define point<%> (interface () get-x get-y))
(define colored-point<%> (interface (point<%>) color)) (define colored-point<%> (interface (point<%>) color))
@ -2581,7 +2611,7 @@ Returns @racket[#t] if @racket[intf] (or any of its ancestor
interfaces) includes a member with the name @racket[sym], @racket[#f] interfaces) includes a member with the name @racket[sym], @racket[#f]
otherwise. otherwise.
@defexamples[#:eval class-eval @examples[#:eval class-eval
(define i<%> (interface () get-x get-y)) (define i<%> (interface () get-x get-y))
(method-in-interface? 'get-x i<%>) (method-in-interface? 'get-x i<%>)
(method-in-interface? 'get-z i<%>) (method-in-interface? 'get-z i<%>)
@ -2595,7 +2625,7 @@ including methods inherited from superinterfaces, but not including
methods whose names are local (i.e., declared with methods whose names are local (i.e., declared with
@racket[define-local-member-name]). @racket[define-local-member-name]).
@defexamples[#:eval class-eval @examples[#:eval class-eval
(define i<%> (interface () get-x get-y)) (define i<%> (interface () get-x get-y))
(interface->method-names i<%>) (interface->method-names i<%>)
]} ]}
@ -2607,7 +2637,7 @@ methods whose names are local (i.e., declared with
Returns @racket[#t] if @racket[object] has a method named @racket[sym] Returns @racket[#t] if @racket[object] has a method named @racket[sym]
that accepts @racket[cnt] arguments, @racket[#f] otherwise. that accepts @racket[cnt] arguments, @racket[#f] otherwise.
@defexamples[#:eval class-eval @examples[#:eval class-eval
(define c% (define c%
(class object% (class object%
(super-new) (super-new)
@ -2628,7 +2658,7 @@ Returns a list of all of the names of the fields bound in
not including fields whose names are local (i.e., declared with not including fields whose names are local (i.e., declared with
@racket[define-local-member-name]). @racket[define-local-member-name]).
@defexamples[#:eval class-eval @examples[#:eval class-eval
(field-names (new object%)) (field-names (new object%))
(field-names (new (class object% (super-new) (field [x 0] [y 0])))) (field-names (new (class object% (super-new) (field [x 0] [y 0]))))
]} ]}

View File

@ -440,13 +440,14 @@ Returns a contract that recognizes a list whose every element matches
the contract @racket[c]. Beware that when this contract is applied to the contract @racket[c]. Beware that when this contract is applied to
a value, the result is not necessarily @racket[eq?] to the input. a value, the result is not necessarily @racket[eq?] to the input.
@examples[#:eval (contract-eval) @examples[#:eval (contract-eval) #:once
(define/contract some-numbers (define/contract some-numbers
(listof number?) (listof number?)
(list 1 2 3)) (list 1 2 3))
(define/contract just-one-number (eval:error
(listof number?) (define/contract just-one-number
11)] (listof number?)
11))]
} }
@ -457,14 +458,15 @@ Returns a contract that recognizes non-empty lists whose elements match
the contract @racket[c]. Beware that when this contract is applied to the contract @racket[c]. Beware that when this contract is applied to
a value, the result is not necessarily @racket[eq?] to the input. a value, the result is not necessarily @racket[eq?] to the input.
@examples[#:eval (contract-eval) @examples[#:eval (contract-eval) #:once
(define/contract some-numbers (define/contract some-numbers
(non-empty-listof number?) (non-empty-listof number?)
(list 1 2 3)) (list 1 2 3))
(define/contract not-enough-numbers (eval:error
(non-empty-listof number?) (define/contract not-enough-numbers
(list))] (non-empty-listof number?)
(list)))]
} }
@defproc[(list*of [c contract?]) contract?]{ @defproc[(list*of [c contract?]) contract?]{
@ -476,14 +478,15 @@ its @racket[cdr] position is expected to be @racket[(list*of c)]. Otherwise,
it is expected to match @racket[c]. Beware that when this contract is applied to it is expected to match @racket[c]. Beware that when this contract is applied to
a value, the result is not necessarily @racket[eq?] to the input. a value, the result is not necessarily @racket[eq?] to the input.
@examples[#:eval (contract-eval) @examples[#:eval (contract-eval) #:once
(define/contract improper-numbers (define/contract improper-numbers
(list*of number?) (list*of number?)
(cons 1 (cons 2 3))) (cons 1 (cons 2 3)))
(define/contract not-improper-numbers (eval:error
(list*of number?) (define/contract not-improper-numbers
(list 1 2 3))] (list*of number?)
(list 1 2 3)))]
@history[#:added "6.1.1.1"] @history[#:added "6.1.1.1"]
} }
@ -499,14 +502,15 @@ necessarily @racket[eq?] to the input.
If the @racket[cdr-c] contract is a @racket[list-contract?], then If the @racket[cdr-c] contract is a @racket[list-contract?], then
@racket[cons/c] returns a @racket[list-contract?]. @racket[cons/c] returns a @racket[list-contract?].
@examples[#:eval (contract-eval) @examples[#:eval (contract-eval) #:once
(define/contract a-pair-of-numbers (define/contract a-pair-of-numbers
(cons/c number? number?) (cons/c number? number?)
(cons 1 2)) (cons 1 2))
(define/contract not-a-pair-of-numbers (eval:error
(cons/c number? number?) (define/contract not-a-pair-of-numbers
(cons #f #t))] (cons/c number? number?)
(cons #f #t)))]
@history[#:changed "6.0.1.13" @list{Added the @racket[list-contract?] propagating behavior.}] @history[#:changed "6.0.1.13" @list{Added the @racket[list-contract?] propagating behavior.}]
} }
@ -525,14 +529,15 @@ In the first case, the contract on the @racket[cdr-id] portion of the contract
may depend on the value in the @racket[car-id] portion of the pair and in may depend on the value in the @racket[car-id] portion of the pair and in
the second case, the reverse is true. the second case, the reverse is true.
@examples[#:eval (contract-eval) @examples[#:eval (contract-eval) #:once
(define/contract an-ordered-pair-of-reals (define/contract an-ordered-pair-of-reals
(cons/dc [hd real?] [tl (hd) (>=/c hd)]) (cons/dc [hd real?] [tl (hd) (>=/c hd)])
(cons 1 2)) (cons 1 2))
(define/contract not-an-ordered-pair-of-reals (eval:error
(cons/dc [hd real?] [tl (hd) (>=/c hd)]) (define/contract not-an-ordered-pair-of-reals
(cons 2 1))] (cons/dc [hd real?] [tl (hd) (>=/c hd)])
(cons 2 1)))]
@history[#:added "6.1.1.6"] @history[#:added "6.1.1.6"]
} }
@ -653,7 +658,7 @@ Produces a contract on parameters whose values must match
@racket[_out]. When the value in the contracted parameter @racket[_out]. When the value in the contracted parameter
is set, it must match @racket[_in]. is set, it must match @racket[_in].
@examples[#:eval (contract-eval) @examples[#:eval (contract-eval) #:once
(define/contract current-snack (define/contract current-snack
(parameter/c string?) (parameter/c string?)
(make-parameter "potato-chip")) (make-parameter "potato-chip"))
@ -663,9 +668,10 @@ is set, it must match @racket[_in].
(parameter/c string? baked/c) (parameter/c string? baked/c)
(make-parameter "turkey" (λ (s) (string-append "roasted " s)))) (make-parameter "turkey" (λ (s) (string-append "roasted " s))))
(current-snack 'not-a-snack) (eval:error (current-snack 'not-a-snack))
(parameterize ([current-dinner "tofurkey"]) (eval:error
(current-dinner)) (parameterize ([current-dinner "tofurkey"])
(current-dinner)))
]} ]}
@ -683,18 +689,18 @@ Produces a contract for procedures that accept @racket[n] argument
Produces a contract that recognizes @racket[hash] tables with keys and values Produces a contract that recognizes @racket[hash] tables with keys and values
as specified by the @racket[key] and @racket[val] arguments. as specified by the @racket[key] and @racket[val] arguments.
@examples[#:eval @examples[#:eval (contract-eval) #:once
(contract-eval)
(define/contract good-hash (define/contract good-hash
(hash/c integer? boolean?) (hash/c integer? boolean?)
(hash 1 #t (hash 1 #t
2 #f 2 #f
3 #t)) 3 #t))
(define/contract bad-hash (eval:error
(hash/c integer? boolean?) (define/contract bad-hash
(hash 1 "elephant" (hash/c integer? boolean?)
2 "monkey" (hash 1 "elephant"
3 "manatee"))] 2 "monkey"
3 "manatee")))]
There are a number of technicalities that control how @racket[hash/c] contracts There are a number of technicalities that control how @racket[hash/c] contracts
behave. behave.
@ -703,17 +709,15 @@ behave.
a flat contract, and the @racket[key] and @racket[val] arguments must also be flat a flat contract, and the @racket[key] and @racket[val] arguments must also be flat
contracts. contracts.
@examples[#:eval @examples[#:eval (contract-eval) #:once
(contract-eval)
(flat-contract? (hash/c integer? boolean?)) (flat-contract? (hash/c integer? boolean?))
(flat-contract? (hash/c integer? boolean? #:flat? #t)) (flat-contract? (hash/c integer? boolean? #:flat? #t))
(hash/c integer? (-> integer? integer?) #:flat? #t)] (eval:error (hash/c integer? (-> integer? integer?) #:flat? #t))]
Such flat contracts will be unsound if applied to mutable hash tables, Such flat contracts will be unsound if applied to mutable hash tables,
as they will not check future mutations to the hash table. as they will not check future mutations to the hash table.
@examples[#:eval @examples[#:eval (contract-eval) #:once
(contract-eval)
(define original-h (make-hasheq)) (define original-h (make-hasheq))
(define/contract ctc-h (define/contract ctc-h
(hash/c integer? boolean? #:flat? #t) (hash/c integer? boolean? #:flat? #t)
@ -725,15 +729,13 @@ If the @racket[immutable] argument is @racket[#t] and the @racket[key] and
@racket[val] arguments are @racket[flat-contract?]s, the result will be a @racket[val] arguments are @racket[flat-contract?]s, the result will be a
@racket[flat-contract?]. @racket[flat-contract?].
@examples[#:eval @examples[#:eval (contract-eval) #:once
(contract-eval)
(flat-contract? (hash/c integer? boolean? #:immutable #t))] (flat-contract? (hash/c integer? boolean? #:immutable #t))]
If either the domain or the range is a @racket[chaperone-contract?], then the result will If either the domain or the range is a @racket[chaperone-contract?], then the result will
be a @racket[chaperone-contract?]. be a @racket[chaperone-contract?].
@examples[#:eval @examples[#:eval (contract-eval) #:once
(contract-eval)
(flat-contract? (hash/c (-> integer? integer?) boolean? (flat-contract? (hash/c (-> integer? integer?) boolean?
#:immutable #t)) #:immutable #t))
(chaperone-contract? (hash/c (-> integer? integer?) boolean? (chaperone-contract? (hash/c (-> integer? integer?) boolean?
@ -744,11 +746,11 @@ be a @racket[chaperone-contract?].
If the @racket[key] argument is a @racket[chaperone-contract?] but not a If the @racket[key] argument is a @racket[chaperone-contract?] but not a
@racket[flat-contract?], then the resulting contract @racket[flat-contract?], then the resulting contract
can be applied only to @racket[equal?]-based hash tables. can be applied only to @racket[equal?]-based hash tables.
@examples[#:eval @examples[#:eval (contract-eval) #:once
(contract-eval) (eval:error
(define/contract h (define/contract h
(hash/c (-> integer? integer?) any/c) (hash/c (-> integer? integer?) any/c)
(make-hasheq))] (make-hasheq)))]
Also, when such a @racket[hash/c] contract is applied to a hash table, the result is not Also, when such a @racket[hash/c] contract is applied to a hash table, the result is not
@racket[eq?] @racket[eq?]
to the input. The result of applying the contract will be a copy for immutable hash tables, to the input. The result of applying the contract will be a copy for immutable hash tables,
@ -777,16 +779,16 @@ for mutable hash tables.
and it may also be @racket['impersonator], in which case they may be any @racket[contract?]s. and it may also be @racket['impersonator], in which case they may be any @racket[contract?]s.
The default is @racket['chaperone]. The default is @racket['chaperone].
@examples[#:eval @examples[#:eval (contract-eval) #:once
(contract-eval)
(define/contract h (define/contract h
(hash/dc [k real?] [v (k) (>=/c k)]) (hash/dc [k real?] [v (k) (>=/c k)])
(hash 1 3 (hash 1 3
2 4)) 2 4))
(define/contract h (eval:error
(hash/dc [k real?] [v (k) (>=/c k)]) (define/contract h
(hash 3 1 (hash/dc [k real?] [v (k) (>=/c k)])
4 2))] (hash 3 1
4 2)))]
} }
@ -801,12 +803,12 @@ is a chaperone contract. Otherwise, the resulting contract is an impersonator
contract. When a channel contract is applied to a channel, the resulting channel contract. When a channel contract is applied to a channel, the resulting channel
is not @racket[eq?] to the input. is not @racket[eq?] to the input.
@examples[#:eval (contract-eval) @examples[#:eval (contract-eval) #:once
(define/contract chan (define/contract chan
(channel/c string?) (channel/c string?)
(make-channel)) (make-channel))
(thread (λ () (channel-get chan))) (thread (λ () (channel-get chan)))
(channel-put chan 'not-a-string) (eval:error (channel-put chan 'not-a-string))
]} ]}
@ -832,19 +834,20 @@ If @racket[maybe-call/cc] is provided, then the provided contracts
are used to check the return values from a continuation captured with are used to check the return values from a continuation captured with
@racket[call-with-current-continuation]. @racket[call-with-current-continuation].
@examples[#:eval (contract-eval) @examples[#:eval (contract-eval) #:once
(define/contract tag (define/contract tag
(prompt-tag/c (-> number? string?)) (prompt-tag/c (-> number? string?))
(make-continuation-prompt-tag)) (make-continuation-prompt-tag))
(call-with-continuation-prompt (eval:error
(lambda () (call-with-continuation-prompt
(number->string (lambda ()
(call-with-composable-continuation (number->string
(lambda (k) (call-with-composable-continuation
(abort-current-continuation tag k))))) (lambda (k)
tag (abort-current-continuation tag k)))))
(lambda (k) (k "not a number"))) tag
(lambda (k) (k "not a number"))))
] ]
} }
@ -858,17 +861,18 @@ If the argument @racket[contract] is a chaperone contract, the resulting
contract will also be a @tech{chaperone} contract. Otherwise, the contract is contract will also be a @tech{chaperone} contract. Otherwise, the contract is
an @tech{impersonator} contract. an @tech{impersonator} contract.
@examples[#:eval (contract-eval) @examples[#:eval (contract-eval) #:once
(define/contract mark-key (define/contract mark-key
(continuation-mark-key/c (-> symbol? (listof symbol?))) (continuation-mark-key/c (-> symbol? (listof symbol?)))
(make-continuation-mark-key)) (make-continuation-mark-key))
(with-continuation-mark (eval:error
mark-key (with-continuation-mark
(lambda (s) (append s '(truffle fudge ganache))) mark-key
(let ([mark-value (continuation-mark-set-first (lambda (s) (append s '(truffle fudge ganache)))
(current-continuation-marks) mark-key)]) (let ([mark-value (continuation-mark-set-first
(mark-value "chocolate-bar"))) (current-continuation-marks) mark-key)])
(mark-value "chocolate-bar"))))
] ]
} }
@ -880,7 +884,7 @@ Returns a contract that recognizes @tech{synchronizable event}s whose
The resulting contract is always a @tech{chaperone} contract and its The resulting contract is always a @tech{chaperone} contract and its
arguments must all be chaperone contracts. arguments must all be chaperone contracts.
@defexamples[#:eval (contract-eval) @examples[#:eval (contract-eval) #:once
(define/contract my-evt (define/contract my-evt
(evt/c evt?) (evt/c evt?)
always-evt) always-evt)
@ -888,7 +892,7 @@ arguments must all be chaperone contracts.
(evt/c number? number?) (evt/c number? number?)
(alarm-evt (+ (current-inexact-milliseconds) 50))) (alarm-evt (+ (current-inexact-milliseconds) 50)))
(sync my-evt) (sync my-evt)
(sync failing-evt) (eval:error (sync failing-evt))
] ]
} }
@ -1372,14 +1376,14 @@ by some @racket[x] in positive position with respect to @racket[parametric->/c])
are checked for the appropriate wrapper. If they have it, they are unwrapped; are checked for the appropriate wrapper. If they have it, they are unwrapped;
if they do not, a contract violation is signaled. if they do not, a contract violation is signaled.
@examples[#:eval (contract-eval) @examples[#:eval (contract-eval) #:once
(define/contract (check x y) (define/contract (check x y)
(parametric->/c [X] (boolean? X . -> . X)) (parametric->/c [X] (boolean? X . -> . X))
(if (or (not x) (equal? y 'surprise)) (if (or (not x) (equal? y 'surprise))
'invalid 'invalid
y)) y))
(check #t 'ok) (check #t 'ok)
(check #f 'ignored) (eval:error (check #f 'ignored))
(check #t 'surprise) (check #t 'surprise)
] ]
} }
@ -1589,8 +1593,7 @@ the export.
should be reported in terms of the public module instead of the should be reported in terms of the public module instead of the
private one. private one.
@examples[#:eval @examples[#:eval (contract-eval) #:once
(contract-eval)
(module private-implementation racket/base (module private-implementation racket/base
(require racket/contract) (require racket/contract)
(define (recip x) (/ 1 x)) (define (recip x) (/ 1 x))
@ -1603,7 +1606,7 @@ the export.
(provide (recontract-out recip))) (provide (recontract-out recip)))
(require 'public) (require 'public)
(recip +nan.0)] (eval:error (recip +nan.0))]
Replacing the use of @racket[recontract-out] with just Replacing the use of @racket[recontract-out] with just
@racket[recip] would result in a contract violation blaming @racket[recip] would result in a contract violation blaming
@ -1671,7 +1674,7 @@ For the definition of @racket[free-var-list], see @racket[with-contract].
(-> real? real?) (-> real? real?)
(* 660 fr)) (* 660 fr))
(code:comment "a contract violation expected here:") (code:comment "a contract violation expected here:")
(furlongs->feet "not a furlong") (eval:error (furlongs->feet "not a furlong"))
] ]
The @racket[define/contract] form treats the individual definition as The @racket[define/contract] form treats the individual definition as
@ -1682,7 +1685,7 @@ positions of the contract. Since the contract boundary is
between the definition and the surrounding context, references to between the definition and the surrounding context, references to
@racket[id] inside the @racket[define/contract] form are not checked. @racket[id] inside the @racket[define/contract] form are not checked.
@examples[#:eval (contract-eval) @examples[#:eval (contract-eval) #:once
(code:comment "an unsual predicate that prints when called") (code:comment "an unsual predicate that prints when called")
(define (printing-int? x) (define (printing-int? x)
(displayln "I was called") (displayln "I was called")
@ -1692,7 +1695,7 @@ between the definition and the surrounding context, references to
(if (zero? n) (if (zero? n)
1 1
(* n (fact (sub1 n))))) (* n (fact (sub1 n)))))
(fact 5) (code:comment "only prints twice, not for each recursive call") (code:line (fact 5) (code:comment "only prints twice, not for each recursive call"))
] ]
If a free-var-list is given, then any uses of the free variables If a free-var-list is given, then any uses of the free variables
@ -1700,7 +1703,7 @@ inside the @racket[body] will be protected with contracts that
blame the context of the @racket[define/contract] form for the positive blame the context of the @racket[define/contract] form for the positive
positions and the @racket[define/contract] form for the negative ones. positions and the @racket[define/contract] form for the negative ones.
@examples[#:eval (contract-eval) @examples[#:eval (contract-eval) #:once
(define (integer->binary-string n) (define (integer->binary-string n)
(number->string n 2)) (number->string n 2))
(define/contract (numbers->strings lst) (define/contract (numbers->strings lst)
@ -1708,7 +1711,7 @@ positions and the @racket[define/contract] form for the negative ones.
#:freevar integer->binary-string (-> exact-integer? string?) #:freevar integer->binary-string (-> exact-integer? string?)
(code:comment "mistake, lst might contain inexact numbers") (code:comment "mistake, lst might contain inexact numbers")
(map integer->binary-string lst)) (map integer->binary-string lst))
(numbers->strings '(4.0 3.3 5.8)) (eval:error (numbers->strings '(4.0 3.3 5.8)))
]} ]}
@defform*[[(define-struct/contract struct-id ([field contract-expr] ...) @defform*[[(define-struct/contract struct-id ([field contract-expr] ...)
@ -1725,15 +1728,15 @@ The @racket[define-struct/contract] form only allows a subset of the
@racket[#:auto-value], @racket[#:omit-define-syntaxes], @racket[#:property] and @racket[#:auto-value], @racket[#:omit-define-syntaxes], @racket[#:property] and
@racket[#:omit-define-values]. @racket[#:omit-define-values].
@examples[#:eval (contract-eval) @examples[#:eval (contract-eval) #:once
(define-struct/contract fish ([color number?])) (define-struct/contract fish ([color number?]))
(make-fish 5) (make-fish 5)
(make-fish #f) (eval:error (make-fish #f))
(define-struct/contract (salmon fish) ([ocean symbol?])) (define-struct/contract (salmon fish) ([ocean symbol?]))
(make-salmon 5 'atlantic) (make-salmon 5 'atlantic)
(make-salmon 5 #f) (eval:error (make-salmon 5 #f))
(make-salmon #f 'pacific) (eval:error (make-salmon #f 'pacific))
]} ]}
@defform[(invariant-assertion invariant-expr expr)]{ @defform[(invariant-assertion invariant-expr expr)]{
@ -1766,7 +1769,7 @@ The @racket[define-struct/contract] form only allows a subset of the
(furlongss->feets (list 1 2 3)) (furlongss->feets (list 1 2 3))
(furlongss->feets (list 1 327 3))] (eval:error (furlongss->feets (list 1 327 3)))]
@history[#:added "6.0.1.11"] @history[#:added "6.0.1.11"]
@ -1810,8 +1813,7 @@ The @racket[define-struct/contract] form only allows a subset of the
it can be any of the things that the third argument to @racket[datum->syntax] it can be any of the things that the third argument to @racket[datum->syntax]
can be. can be.
@examples[#:eval @examples[#:eval (contract-eval) #:once
(contract-eval)
(module server racket/base (module server racket/base
(require racket/contract/base) (require racket/contract/base)
(define (f x) #f) (define (f x) #f)
@ -1823,8 +1825,8 @@ The @racket[define-struct/contract] form only allows a subset of the
(define (servers-fault) (g 1)) (define (servers-fault) (g 1))
(provide servers-fault clients-fault)) (provide servers-fault clients-fault))
(require 'client) (require 'client)
(clients-fault) (eval:error (clients-fault))
(servers-fault)] (eval:error (servers-fault))]
} }
@ -1856,10 +1858,9 @@ produces @racket[#f], no name is printed. Otherwise, it is also formatted as by
@racket[display]. More precisely, the @racket[value-name-expr] ends up in the @racket[display]. More precisely, the @racket[value-name-expr] ends up in the
@racket[blame-name] field of the blame record, which is used as the first portion @racket[blame-name] field of the blame record, which is used as the first portion
of the error message. of the error message.
@examples[#:eval @examples[#:eval (contract-eval) #:once
(contract-eval) (eval:error (contract integer? #f 'pos 'neg 'timothy #f))
(contract integer? #f 'pos 'neg 'timothy #f) (eval:error (contract integer? #f 'pos 'neg #f #f))]
(contract integer? #f 'pos 'neg #f #f)]
If specified, @racket[source-location-expr] indicates the source location If specified, @racket[source-location-expr] indicates the source location
reported by contract violations. The expression must produce a @racket[srcloc] reported by contract violations. The expression must produce a @racket[srcloc]
@ -2016,11 +2017,11 @@ was passed as the second argument to @racket[contract-stronger?].
The @racket[is-list-contract?] argument is used by the @racket[list-contract?] predicate The @racket[is-list-contract?] argument is used by the @racket[list-contract?] predicate
to determine if this is a contract that accepts only @racket[list?] values. to determine if this is a contract that accepts only @racket[list?] values.
@defexamples[#:eval (contract-eval) @examples[#:eval (contract-eval) #:once
(define int/c (define int/c
(make-flat-contract #:name 'int/c #:first-order integer?)) (make-flat-contract #:name 'int/c #:first-order integer?))
(contract int/c 1 'positive 'negative) (contract int/c 1 'positive 'negative)
(contract int/c "not one" 'positive 'negative) (eval:error (contract int/c "not one" 'positive 'negative))
(int/c 1) (int/c 1)
(int/c "not one") (int/c "not one")
(define int->int/c (define int->int/c
@ -2039,12 +2040,12 @@ to determine if this is a contract that accepts only @racket[list?] values.
b f b f
'(expected "a function of one argument" given: "~e") '(expected "a function of one argument" given: "~e")
f))))))) f)))))))
(contract int->int/c "not fun" 'positive 'negative) (eval:error (contract int->int/c "not fun" 'positive 'negative))
(define halve (define halve
(contract int->int/c (λ (x) (/ x 2)) 'positive 'negative)) (contract int->int/c (λ (x) (/ x 2)) 'positive 'negative))
(halve 2) (halve 2)
(halve 1/2) (eval:error (halve 1/2))
(halve 1) (eval:error (halve 1))
] ]
@history[#:changed "6.0.1.13" @list{Added the @racket[#:list-contract?] argument.}] @history[#:changed "6.0.1.13" @list{Added the @racket[#:list-contract?] argument.}]
@ -2154,12 +2155,12 @@ contracts. The error messages assume that the function named by
or @racket["a conjunct of"] (in the case of an @racket[and/c] contract). or @racket["a conjunct of"] (in the case of an @racket[and/c] contract).
For example, consider this contract violation: For example, consider this contract violation:
@interaction[#:eval (contract-eval) @examples[#:label #f #:eval (contract-eval) #:once
(define/contract f (define/contract f
(list/c (-> integer? integer?)) (list/c (-> integer? integer?))
(list (λ (x) x))) (list (λ (x) x)))
((car f) #f) (eval:error ((car f) #f))
] ]
It shows that the portion of the contract being violated is the first It shows that the portion of the contract being violated is the first
occurrence of @racket[integer?], because the @racket[->] and occurrence of @racket[integer?], because the @racket[->] and
@ -2293,7 +2294,7 @@ returns a string that is put into the contract error
message. Note that the value is often already included in message. Note that the value is often already included in
the message that indicates the violation. the message that indicates the violation.
@defexamples[#:eval (contract-eval) @examples[#:eval (contract-eval) #:once
(define (show-blame-error blame value message) (define (show-blame-error blame value message)
(string-append (string-append
"Contract Violation!\n" "Contract Violation!\n"
@ -2309,8 +2310,8 @@ the message that indicates the violation.
(-> integer? integer?) (-> integer? integer?)
(/ x 2)) (/ x 2))
(f 2) (f 2)
(f 1) (eval:error (f 1))
(f 1/2) (eval:error (f 1/2))
] ]
} }
@ -2697,7 +2698,7 @@ are below):
This function is conservative, so it may return @racket[#f] when This function is conservative, so it may return @racket[#f] when
@racket[x] does, in fact, accept fewer values. @racket[x] does, in fact, accept fewer values.
@examples[#:eval (contract-eval) @examples[#:eval (contract-eval) #:once
(contract-stronger? integer? integer?) (contract-stronger? integer? integer?)
(contract-stronger? (between/c 25 75) (between/c 0 100)) (contract-stronger? (between/c 25 75) (between/c 0 100))
(contract-stronger? (between/c 0 100) (between/c 25 75)) (contract-stronger? (between/c 0 100) (between/c 25 75))
@ -2851,13 +2852,15 @@ expression, then @racket[opt/c] raises an error using
@racket[id] as the name of the primitive, instead of using @racket[id] as the name of the primitive, instead of using
the name @racket[opt/c]. the name @racket[opt/c].
@examples[#:eval (contract-eval) @examples[#:eval (contract-eval) #:once
(define/contract (f x) (eval:error
(opt/c '(not-a-contract)) (define/contract (f x)
x) (opt/c '(not-a-contract))
(define/contract (f x) x))
(opt/c '(not-a-contract) #:error-name define/contract) (eval:error
x)] (define/contract (f x)
(opt/c '(not-a-contract) #:error-name define/contract)
x))]
} }

View File

@ -455,7 +455,7 @@ The arguments implement the port as follows:
;; The port doesn't supply procedures to implement progress events: ;; The port doesn't supply procedures to implement progress events:
(port-provides-progress-evts? infinite-ones) (port-provides-progress-evts? infinite-ones)
(port-progress-evt infinite-ones) (eval:error (port-progress-evt infinite-ones))
;; Non-byte port results: ;; Non-byte port results:
(define infinite-voids (define infinite-voids
@ -464,7 +464,7 @@ The arguments implement the port as follows:
(lambda (s) (lambda args 'void)) (lambda (s) (lambda args 'void))
(lambda (skip s evt) (lambda args 'void)) (lambda (skip s evt) (lambda args 'void))
void)) void))
(read-char infinite-voids) (eval:error (read-char infinite-voids))
(read-char-or-special infinite-voids) (read-char-or-special infinite-voids)
;; This port produces 0, 1, 2, 0, 1, 2, etc., but it is not ;; This port produces 0, 1, 2, 0, 1, 2, etc., but it is not

View File

@ -47,25 +47,27 @@ angle brackets in @racket[write] and @racket[print] mode and no brackets in
@racket[display] mode. Elements of the tuple are printed recursively, @racket[display] mode. Elements of the tuple are printed recursively,
so that graph and cycle structure can be represented. so that graph and cycle structure can be represented.
@defexamples[ @examples[
(define (tuple-print tuple port mode) (eval:no-prompt
(when mode (write-string "<" port)) (define (tuple-print tuple port mode)
(let ([l (tuple-ref tuple)] (when mode (write-string "<" port))
[recur (case mode (let ([l (tuple-ref tuple)]
[(#t) write] [recur (case mode
[(#f) display] [(#t) write]
[else (lambda (p port) (print p port mode))])]) [(#f) display]
(unless (zero? (vector-length l)) [else (lambda (p port) (print p port mode))])])
(recur (vector-ref l 0) port) (unless (zero? (vector-length l))
(for-each (lambda (e) (recur (vector-ref l 0) port)
(write-string ", " port) (for-each (lambda (e)
(recur e port)) (write-string ", " port)
(cdr (vector->list l))))) (recur e port))
(when mode (write-string ">" port))) (cdr (vector->list l)))))
(when mode (write-string ">" port))))
(struct tuple (ref) (eval:no-prompt
#:methods gen:custom-write (struct tuple (ref)
[(define write-proc tuple-print)]) #:methods gen:custom-write
[(define write-proc tuple-print)]))
(display (tuple #(1 2 "a"))) (display (tuple #(1 2 "a")))

View File

@ -3,8 +3,8 @@
racket/generic)) racket/generic))
@(define posn-eval (make-base-eval)) @(define posn-eval (make-base-eval))
@(interaction-eval #:eval posn-eval @examples[#:hidden #:eval posn-eval
(require racket/match racket/stream (for-syntax racket/base))) (require racket/match racket/stream (for-syntax racket/base))]
@title[#:tag "define-struct"]{Defining Structure Types: @racket[struct]} @title[#:tag "define-struct"]{Defining Structure Types: @racket[struct]}
@ -141,7 +141,7 @@ multiple times, attaches a property value to the structure type; see
(unless (and (real? temp) (>= temp -273.15)) (unless (and (real? temp) (>= temp -273.15))
(error "not a valid temperature")) (error "not a valid temperature"))
temp)) temp))
(celsius -275) (eval:error (celsius -275))
] ]
@margin-note{Use the @racket[prop:procedure] property to implement an @margin-note{Use the @racket[prop:procedure] property to implement an
@ -195,7 +195,7 @@ name, as do the various procedures that are bound by @racket[struct].
@examples[#:eval posn-eval @examples[#:eval posn-eval
(struct circle (radius) #:reflection-name '<circle>) (struct circle (radius) #:reflection-name '<circle>)
(circle 15) (circle 15)
(circle-radius "bad") (eval:error (circle-radius "bad"))
] ]
If @racket[#:methods gen:name method-defs] is provided, then If @racket[#:methods gen:name method-defs] is provided, then
@ -225,11 +225,12 @@ supplied, then the @racket[struct] form is equivalent to
@examples[#:eval posn-eval @examples[#:eval posn-eval
(struct square (side) #:omit-define-syntaxes) (struct square (side) #:omit-define-syntaxes)
(match (square 5) (eval:error
(code:comment "fails to match because syntax is omitted") (match (square 5)
[(struct square x) x]) (code:comment "fails to match because syntax is omitted")
[(struct square x) x]))
(struct ellipse (width height) #:omit-define-values) (struct ellipse (width height) #:omit-define-values)
ellipse-width (eval:error ellipse-width)
] ]
If @racket[#:auto] is supplied as a @racket[field-option], then the If @racket[#:auto] is supplied as a @racket[field-option], then the
@ -247,20 +248,20 @@ error is reported. If any @racket[field-option] or
@racket[struct-option] keyword is repeated, other than @racket[struct-option] keyword is repeated, other than
@racket[#:property], a syntax error is reported. @racket[#:property], a syntax error is reported.
@defexamples[ @examples[
#:eval posn-eval #:eval posn-eval
(struct posn (x y [z #:auto]) (eval:no-prompt
#:auto-value 0 (struct posn (x y [z #:auto #:mutable])
#:transparent) #:auto-value 0
#:transparent))
(posn 1 2) (posn 1 2)
(posn? (posn 1 2)) (posn? (posn 1 2))
(posn-y (posn 1 2)) (posn-y (posn 1 2))
] (posn-z (posn 1 2))
@defs+int[ (eval:no-prompt
#:eval posn-eval (struct color-posn posn (hue) #:mutable)
[(struct color-posn posn (hue) #:mutable) (define cp (color-posn 1 2 "blue")))
(define cp (color-posn 1 2 "blue"))]
(color-posn-hue cp) (color-posn-hue cp)
cp cp
(set-posn-z! cp 3) (set-posn-z! cp 3)
@ -280,11 +281,12 @@ expression is an exact, non-negative integer that corresponds to the
position within the structure declaration of the field named by position within the structure declaration of the field named by
@racket[field-id]. @racket[field-id].
@defexamples[ @examples[
#:eval posn-eval #:eval posn-eval
(struct mood-procedure (base rating) (eval:no-prompt
#:property prop:procedure (struct-field-index base)) (struct mood-procedure (base rating)
(define happy+ (mood-procedure add1 10)) #:property prop:procedure (struct-field-index base))
(define happy+ (mood-procedure add1 10)))
(happy+ 2) (happy+ 2)
(mood-procedure-rating happy+) (mood-procedure-rating happy+)
]} ]}
@ -305,11 +307,12 @@ provided.
This form is provided for backwards compatibility; @racket[struct] is This form is provided for backwards compatibility; @racket[struct] is
preferred. preferred.
@defexamples[ @examples[
#:eval posn-eval #:eval posn-eval
(define-struct posn (x y [z #:auto]) (eval:no-prompt
#:auto-value 0 (define-struct posn (x y [z #:auto])
#:transparent) #:auto-value 0
#:transparent))
(make-posn 1 2) (make-posn 1 2)
(posn? (make-posn 1 2)) (posn? (make-posn 1 2))
(posn-y (make-posn 1 2)) (posn-y (make-posn 1 2))
@ -326,20 +329,21 @@ the sub-form for error reporting is that it starts with @racket[id].
The @racket[define-struct/derived] form is intended for use by macros The @racket[define-struct/derived] form is intended for use by macros
that expand to @racket[define-struct]. that expand to @racket[define-struct].
@defexamples[ @examples[
#:eval posn-eval #:eval posn-eval
(define-syntax (define-xy-struct stx) (eval:no-prompt
(syntax-case stx () (define-syntax (define-xy-struct stx)
[(ds name . rest) (syntax-case stx ()
(with-syntax ([orig stx]) [(ds name . rest)
#'(define-struct/derived orig name (x y) . rest))])) (with-syntax ([orig stx])
#'(define-struct/derived orig name (x y) . rest))])))
(define-xy-struct posn) (define-xy-struct posn)
(posn-x (make-posn 1 2)) (posn-x (make-posn 1 2))
(define-xy-struct posn #:mutable) (define-xy-struct posn #:mutable)
(set-posn-x! (make-posn 1 2) 0) (set-posn-x! (make-posn 1 2) 0)
(code:comment "this next line will cause an error due to a bad keyword") (code:comment "this next line will cause an error due to a bad keyword")
(define-xy-struct posn #:bad-option) (eval:error (define-xy-struct posn #:bad-option))
]} ]}
@; ---------------------------------------- @; ----------------------------------------

View File

@ -1,8 +1,8 @@
#lang scribble/doc #lang scribble/doc
@(require "mz.rkt" scribble/eval (for-label racket/generic)) @(require "mz.rkt" (for-label racket/generic))
@(define dict-eval (make-base-eval)) @(define dict-eval (make-base-eval))
@(interaction-eval #:eval dict-eval (require racket/dict racket/generic)) @examples[#:hidden #:eval dict-eval (require racket/dict racket/generic)]
@title[#:tag "dicts"]{Dictionaries} @title[#:tag "dicts"]{Dictionaries}
@ -200,12 +200,12 @@ result:
@examples[ @examples[
#:eval dict-eval #:eval dict-eval
(dict-ref #hash((a . "apple") (b . "beer")) 'a) (dict-ref #hash((a . "apple") (b . "beer")) 'a)
(dict-ref #hash((a . "apple") (b . "beer")) 'c) (eval:error (dict-ref #hash((a . "apple") (b . "beer")) 'c))
(dict-ref #hash((a . "apple") (b . "beer")) 'c #f) (dict-ref #hash((a . "apple") (b . "beer")) 'c #f)
(dict-ref '((a . "apple") (b . "banana")) 'b) (dict-ref '((a . "apple") (b . "banana")) 'b)
(dict-ref #("apple" "banana") 1) (dict-ref #("apple" "banana") 1)
(dict-ref #("apple" "banana") 3 #f) (dict-ref #("apple" "banana") 3 #f)
(dict-ref #("apple" "banana") -3 #f) (eval:error (dict-ref #("apple" "banana") -3 #f))
]} ]}
@defproc[(dict-set! [dict (and/c dict? (not/c immutable?))] @defproc[(dict-set! [dict (and/c dict? (not/c immutable?))]
@ -461,10 +461,10 @@ Supported for any @racket[dict] that implements @racket[dict-ref] and
@examples[ @examples[
#:eval dict-eval #:eval dict-eval
(dict-ref! (make-hasheq '((a . "apple") (b . "beer"))) 'a) (dict-ref! (make-hasheq '((a . "apple") (b . "beer"))) 'a #f)
(dict-ref! (make-hasheq '((a . "apple") (b . "beer"))) 'c 'cabbage) (dict-ref! (make-hasheq '((a . "apple") (b . "beer"))) 'c 'cabbage)
(define h (make-hasheq '((a . "apple") (b . "beer")))) (define h (make-hasheq '((a . "apple") (b . "beer"))))
(dict-ref h 'c) (eval:error (dict-ref h 'c))
(dict-ref! h 'c (λ () 'cabbage)) (dict-ref! h 'c (λ () 'cabbage))
(dict-ref h 'c) (dict-ref h 'c)
]} ]}
@ -486,7 +486,7 @@ Supported for any @racket[dict] that implements @racket[dict-ref] and
@examples[ @examples[
#:eval dict-eval #:eval dict-eval
(define h (make-hash)) (define h (make-hash))
(dict-update! h 'a add1) (eval:error (dict-update! h 'a add1))
(dict-update! h 'a add1 0) (dict-update! h 'a add1 0)
h h
(define v (vector #f #f #f)) (define v (vector #f #f #f))
@ -512,7 +512,7 @@ Supported for any @racket[dict] that implements @racket[dict-ref] and
@examples[ @examples[
#:eval dict-eval #:eval dict-eval
(dict-update #hash() 'a add1) (eval:error (dict-update #hash() 'a add1))
(dict-update #hash() 'a add1 0) (dict-update #hash() 'a add1 0)
(dict-update #hash((a . "apple") (b . "beer")) 'b string-length) (dict-update #hash((a . "apple") (b . "beer")) 'b string-length)
]} ]}

View File

@ -1,6 +1,5 @@
#lang scribble/doc #lang scribble/doc
@(require scribble/struct @(require scribble/struct
scribble/eval
"mz.rkt" "mz.rkt"
(for-label racket/async-channel)) (for-label racket/async-channel))

View File

@ -103,7 +103,7 @@ exception handler obtains control, and the handler itself is
(+ 5 (raise (make-my-exception (+ 5 (raise (make-my-exception
"failed" "failed"
(current-continuation-marks))))) (current-continuation-marks)))))
(raise 'failed #t) (eval:error (raise 'failed #t))
]} ]}
@defproc*[([(error [sym symbol?]) any] @defproc*[([(error [sym symbol?]) any]
@ -145,9 +145,9 @@ In all cases, the constructed message string is passed to
@racket[make-exn:fail], and the resulting exception is raised. @racket[make-exn:fail], and the resulting exception is raised.
@examples[ @examples[
(error 'failed) (eval:error (error 'failed))
(error "failed" 23 'pizza (list 1 2 3)) (eval:error (error "failed" 23 'pizza (list 1 2 3)))
(error 'method-a "failed because ~a" "no argument supplied") (eval:error (error 'method-a "failed because ~a" "no argument supplied"))
]} ]}
@ -187,17 +187,17 @@ message names the bad argument and also lists the other arguments. If
(if (not (integer? bits)) (if (not (integer? bits))
(raise-argument-error 'feed-machine "integer?" bits) (raise-argument-error 'feed-machine "integer?" bits)
"fed the machine")) "fed the machine"))
(feed-machine 'turkey) (eval:error (feed-machine 'turkey))
(define (feed-cow animal) (define (feed-cow animal)
(if (not (eq? animal 'cow)) (if (not (eq? animal 'cow))
(raise-argument-error 'feed-cow "'cow" animal) (raise-argument-error 'feed-cow "'cow" animal)
"fed the cow")) "fed the cow"))
(feed-cow 'turkey) (eval:error (feed-cow 'turkey))
(define (feed-animals cow sheep goose cat) (define (feed-animals cow sheep goose cat)
(if (not (eq? goose 'goose)) (if (not (eq? goose 'goose))
(raise-argument-error 'feed-animals "'goose" 2 cow sheep goose cat) (raise-argument-error 'feed-animals "'goose" 2 cow sheep goose cat)
"fed the animals")) "fed the animals"))
(feed-animals 'cow 'sheep 'dog 'cat) (eval:error (feed-animals 'cow 'sheep 'dog 'cat))
]} ]}
@ -224,10 +224,11 @@ using the error value conversion handler (see
@racket[error-value->string-handler]). @racket[error-value->string-handler]).
@examples[ @examples[
(eval:error
(raise-arguments-error 'eat (raise-arguments-error 'eat
"fish is smaller than its given meal" "fish is smaller than its given meal"
"fish" 12 "fish" 12
"meal" 13) "meal" 13))
]} ]}
@ -254,10 +255,10 @@ less than} the size of a collection---for example, @racket[(sub1
(vector-length _vec))], @racket[(sub1 (length _lst))], and so on. (vector-length _vec))], @racket[(sub1 (length _lst))], and so on.
@examples[ @examples[
(raise-range-error 'vector-ref "vector" "starting " 5 #(1 2 3 4) 0 3) (eval:error (raise-range-error 'vector-ref "vector" "starting " 5 #(1 2 3 4) 0 3))
(raise-range-error 'vector-ref "vector" "ending " 5 #(1 2 3 4) 0 3) (eval:error (raise-range-error 'vector-ref "vector" "ending " 5 #(1 2 3 4) 0 3))
(raise-range-error 'vector-ref "vector" "" 3 #() 0 -1) (eval:error (raise-range-error 'vector-ref "vector" "" 3 #() 0 -1))
(raise-range-error 'vector-ref "vector" "ending " 1 #(1 2 3 4) 2 3 0) (eval:error (raise-range-error 'vector-ref "vector" "ending " 1 #(1 2 3 4) 2 3 0))
]} ]}

View File

@ -2,7 +2,7 @@
@(require "mz.rkt" (for-label racket/fasl)) @(require "mz.rkt" (for-label racket/fasl))
@(define fasl-eval (make-base-eval)) @(define fasl-eval (make-base-eval))
@(interaction-eval #:eval fasl-eval (require racket/fasl)) @examples[#:hidden #:eval fasl-eval (require racket/fasl)]
@title[#:tag "fasl"]{Fast-Load Serialization} @title[#:tag "fasl"]{Fast-Load Serialization}

View File

@ -27,8 +27,8 @@
(delete-file i))))) (delete-file i)))))
(clean) (clean)
(begin0 (begin0
(defexamples #:eval my-eval (examples #:eval my-eval
expr ...) expr ...)
(clean)))])) (clean)))]))
"") "")

View File

@ -7,7 +7,9 @@
setup/cross-system)) setup/cross-system))
@(define file-eval (make-base-eval)) @(define file-eval (make-base-eval))
@(interaction-eval #:eval file-eval (begin (require racket/file) (define filename (make-temporary-file)))) @examples[#:hidden #:eval file-eval
(require racket/file)
(define filename (make-temporary-file))]
@title{Filesystem} @title{Filesystem}
@ -1428,7 +1430,7 @@ and bitwise operations such as @racket[bitwise-ior], and
@racket[bitwise-and].} @racket[bitwise-and].}
@(interaction-eval #:eval file-eval (begin @examples[#:hidden #:eval file-eval
(delete-file filename) (delete-file filename)
(delete-file (make-lock-file-name filename)))) (delete-file (make-lock-file-name filename))]
@(close-eval file-eval) @(close-eval file-eval)

View File

@ -7,7 +7,7 @@
racket/require)) racket/require))
@(define flfx-eval (make-base-eval)) @(define flfx-eval (make-base-eval))
@(interaction-eval #:eval flfx-eval (require racket/fixnum)) @examples[#:hidden #:eval flfx-eval (require racket/fixnum)]
@title[#:tag "fixnums"]{Fixnums} @title[#:tag "fixnums"]{Fixnums}

View File

@ -2,7 +2,7 @@
@(require "mz.rkt" (for-label racket/flonum)) @(require "mz.rkt" (for-label racket/flonum))
@(define fl-eval (make-base-eval)) @(define fl-eval (make-base-eval))
@(interaction-eval #:eval fl-eval (require racket/flonum)) @examples[#:hidden #:eval fl-eval (require racket/flonum)]
@title[#:tag "flonums"]{Flonums} @title[#:tag "flonums"]{Flonums}

View File

@ -379,10 +379,11 @@ source for all syntax errors.
@code:comment{If we misuse for/digits, we can get good error reporting} @code:comment{If we misuse for/digits, we can get good error reporting}
@code:comment{because the use of orig-datum allows for source correlation:} @code:comment{because the use of orig-datum allows for source correlation:}
(for/digits (eval:error
[a (in-list '(1 2 3))] (for/digits
[b (in-list '(4 5 6))] [a (in-list '(1 2 3))]
(+ a b)) [b (in-list '(4 5 6))]
(+ a b)))
(for/digits (for/digits
([a (in-list '(1 2 3))] ([a (in-list '(1 2 3))]
@ -426,10 +427,11 @@ Like @racket[for*/fold], but the extra @racket[orig-datum] is used as the source
(values (+ n (* d k)) (* k 10)))]) (values (+ n (* d k)) (* k 10)))])
n))])) n))]))
(for*/digits (eval:error
[ds (in-list '((8 3) (1 1)))] (for*/digits
[d (in-list ds)] [ds (in-list '((8 3) (1 1)))]
d) [d (in-list ds)]
d))
(for*/digits (for*/digits
([ds (in-list '((8 3) (1 1)))] ([ds (in-list '((8 3) (1 1)))]

View File

@ -1,7 +1,6 @@
#lang scribble/doc #lang scribble/doc
@(require scribble/manual @(require scribble/manual
scribble/struct scribble/struct
scribble/eval
"mz.rkt" "mz.rkt"
(for-label racket/contract (for-label racket/contract
racket/math racket/math
@ -40,7 +39,7 @@ with @racket[separator] between consecutive items, and then pads or
truncates the string to be at least @racket[min-width] characters and truncates the string to be at least @racket[min-width] characters and
at most @racket[max-width] characters. at most @racket[max-width] characters.
@interaction[#:eval the-eval @examples[#:eval the-eval
(~a "north") (~a "north")
(~a 'south) (~a 'south)
(~a #"east") (~a #"east")
@ -70,7 +69,7 @@ truncated and the end of the string is replaced with
@racket[limit-marker]. If @racket[limit-marker] is longer than @racket[limit-marker]. If @racket[limit-marker] is longer than
@racket[max-width], an exception is raised. @racket[max-width], an exception is raised.
@interaction[#:eval the-eval @examples[#:eval the-eval
(~a "abcde" #:max-width 5) (~a "abcde" #:max-width 5)
(~a "abcde" #:max-width 4) (~a "abcde" #:max-width 4)
(~a "abcde" #:max-width 4 #:limit-marker "*") (~a "abcde" #:max-width 4 #:limit-marker "*")
@ -95,7 +94,7 @@ of @racket[right-pad-string] in its entirety. Thus left padding starts
with the start of @racket[left-pad-string] and right padding ends with with the start of @racket[left-pad-string] and right padding ends with
the end of @racket[right-pad-string]. the end of @racket[right-pad-string].
@interaction[#:eval the-eval @examples[#:eval the-eval
(~a "apple" #:min-width 20 #:align 'left) (~a "apple" #:min-width 20 #:align 'left)
(~a "pear" #:min-width 20 #:align 'left #:right-pad-string " .") (~a "pear" #:min-width 20 #:align 'left #:right-pad-string " .")
(~a "plum" #:min-width 20 #:align 'right #:left-pad-string ". ") (~a "plum" #:min-width 20 #:align 'right #:left-pad-string ". ")
@ -107,7 +106,7 @@ Use @racket[width] to set both @racket[max-width] and @racket[min-width]
simultaneously, ensuring that the resulting string is exactly simultaneously, ensuring that the resulting string is exactly
@racket[width] characters long: @racket[width] characters long:
@interaction[#:eval the-eval @examples[#:label #f #:eval the-eval
(~a "terse" #:width 6) (~a "terse" #:width 6)
(~a "loquacious" #:width 6) (~a "loquacious" #:width 6)
] ]
@ -131,7 +130,7 @@ Like @racket[~a], but each value is converted like @racket[(format
"~v" v)], the default separator is @racket[" "], and the default limit "~v" v)], the default separator is @racket[" "], and the default limit
marker is @racket["..."]. marker is @racket["..."].
@interaction[#:eval the-eval @examples[#:eval the-eval
(~v "north") (~v "north")
(~v 'south) (~v 'south)
(~v #"east") (~v #"east")
@ -141,7 +140,7 @@ marker is @racket["..."].
Use @racket[~v] to produce text that talks about Racket values. Use @racket[~v] to produce text that talks about Racket values.
@interaction[#:eval the-eval @examples[#:eval the-eval
(let ([nums (for/list ([i 10]) i)]) (let ([nums (for/list ([i 10]) i)])
(~a "The even numbers in " (~v nums) (~a "The even numbers in " (~v nums)
" are " (~v (filter even? nums)) ".")) " are " (~v (filter even? nums)) "."))
@ -165,7 +164,7 @@ Like @racket[~a], but each value is converted like @racket[(format
"~s" v)], the default separator is @racket[" "], and the default limit "~s" v)], the default separator is @racket[" "], and the default limit
marker is @racket["..."]. marker is @racket["..."].
@interaction[#:eval the-eval @examples[#:eval the-eval
(~s "north") (~s "north")
(~s 'south) (~s 'south)
(~s #"east") (~s #"east")
@ -192,7 +191,7 @@ Like @racket[~a], but each value is converted like @racket[(format
"~e" v)], the default separator is @racket[" "], and the default limit "~e" v)], the default separator is @racket[" "], and the default limit
marker is @racket["..."]. marker is @racket["..."].
@interaction[#:eval the-eval @examples[#:eval the-eval
(~e "north") (~e "north")
(~e 'south) (~e 'south)
(~e #"east") (~e #"east")
@ -241,7 +240,7 @@ The optional arguments control number formatting:
in positional or exponential notation. If @racket[notation] is a in positional or exponential notation. If @racket[notation] is a
function, it is applied to @racket[x] to get the notation to be used. function, it is applied to @racket[x] to get the notation to be used.
@interaction[#:eval the-eval @examples[#:eval the-eval
(~r 12345) (~r 12345)
(~r 12345 #:notation 'exponential) (~r 12345 #:notation 'exponential)
(let ([pick-notation (let ([pick-notation
@ -266,7 +265,7 @@ point are dropped the decimal point is also dropped. If @racket[precision] is
@racket[(list '= _digits)], then exactly @racket[_digits] digits after the @racket[(list '= _digits)], then exactly @racket[_digits] digits after the
decimal point are used, and the decimal point is never dropped. decimal point are used, and the decimal point is never dropped.
@interaction[#:eval the-eval @examples[#:eval the-eval
(~r pi) (~r pi)
(~r pi #:precision 4) (~r pi #:precision 4)
(~r pi #:precision 0) (~r pi #:precision 0)
@ -282,7 +281,7 @@ with fewer than @racket[min-width] digits (including the decimal
point but not including the sign indicator), the digits are left-padded point but not including the sign indicator), the digits are left-padded
using @racket[pad-string]. using @racket[pad-string].
@interaction[#:eval the-eval @examples[#:eval the-eval
(~r 17) (~r 17)
(~r 17 #:min-width 4) (~r 17 #:min-width 4)
(~r -42 #:min-width 4) (~r -42 #:min-width 4)
@ -298,7 +297,7 @@ number to at least @racket[min-width] characters (not including the
sign indicator). The padding is placed between the sign and the normal sign indicator). The padding is placed between the sign and the normal
digits of @racket[x]. digits of @racket[x].
@interaction[#:eval the-eval @examples[#:eval the-eval
(~r 17 #:min-width 4 #:pad-string "0") (~r 17 #:min-width 4 #:pad-string "0")
(~r -42 #:min-width 4 #:pad-string "0") (~r -42 #:min-width 4 #:pad-string "0")
]} ]}
@ -311,7 +310,7 @@ indicated:
generated if @racket[x] is either positive or zero, and a minus sign is generated if @racket[x] is either positive or zero, and a minus sign is
prefixed if @racket[x] is negative. prefixed if @racket[x] is negative.
@interaction[#:eval the-eval @examples[#:eval the-eval
(for/list ([x '(17 0 -42)]) (~r x)) (for/list ([x '(17 0 -42)]) (~r x))
]} ]}
@ -319,14 +318,14 @@ indicated:
@racket[x] is zero, a plus sign is prefixed if @racket[x] is positive, and a @racket[x] is zero, a plus sign is prefixed if @racket[x] is positive, and a
minus sign is prefixed if @racket[x] is negative. minus sign is prefixed if @racket[x] is negative.
@interaction[#:eval the-eval @examples[#:eval the-eval
(for/list ([x '(17 0 -42)]) (~r x #:sign '+)) (for/list ([x '(17 0 -42)]) (~r x #:sign '+))
]} ]}
@item{If @racket[sign] is @racket['++], a plus sign is prefixed if @racket[x] @item{If @racket[sign] is @racket['++], a plus sign is prefixed if @racket[x]
is zero or positive, and a minus sign is prefixed if @racket[x] is negative. is zero or positive, and a minus sign is prefixed if @racket[x] is negative.
@interaction[#:eval the-eval @examples[#:eval the-eval
(for/list ([x '(17 0 -42)]) (~r x #:sign '++)) (for/list ([x '(17 0 -42)]) (~r x #:sign '++))
]} ]}
@ -334,7 +333,7 @@ indicated:
@racket[x] is zero or positive, and the number is enclosed in parentheses if @racket[x] is zero or positive, and the number is enclosed in parentheses if
@racket[x] is negative. @racket[x] is negative.
@interaction[#:eval the-eval @examples[#:eval the-eval
(for/list ([x '(17 0 -42)]) (~r x #:sign 'parens)) (for/list ([x '(17 0 -42)]) (~r x #:sign 'parens))
]} ]}
@ -344,7 +343,7 @@ indicated:
either a string to be used as a prefix or a list containing two strings: a either a string to be used as a prefix or a list containing two strings: a
prefix and a suffix. prefix and a suffix.
@interaction[#:eval the-eval @examples[#:eval the-eval
(let ([sign-table '(("" " up") "an even " ("" " down"))]) (let ([sign-table '(("" " up") "an even " ("" " down"))])
(for/list ([x '(17 0 -42)]) (~r x #:sign sign-table))) (for/list ([x '(17 0 -42)]) (~r x #:sign sign-table)))
] ]
@ -359,7 +358,7 @@ indicated:
used. If @racket[base] is @racket[(list 'up _base*)] and @racket[_base*] is used. If @racket[base] is @racket[(list 'up _base*)] and @racket[_base*] is
greater than @racket[10], then upper-case letters are used. greater than @racket[10], then upper-case letters are used.
@interaction[#:eval the-eval @examples[#:eval the-eval
(~r 100 #:base 7) (~r 100 #:base 7)
(~r 4.5 #:base 2) (~r 4.5 #:base 2)
(~r 3735928559 #:base 16) (~r 3735928559 #:base 16)
@ -374,7 +373,7 @@ explicit sign (as with a @racket[sign] of @racket['++]) and at least two
digits, separated from the significand by the ``exponent marker'' digits, separated from the significand by the ``exponent marker''
@racket[format-exponent]: @racket[format-exponent]:
@interaction[#:eval the-eval @examples[#:label #f #:eval the-eval
(~r 1234 #:notation 'exponential #:format-exponent "E") (~r 1234 #:notation 'exponential #:format-exponent "E")
] ]
@ -382,7 +381,7 @@ If @racket[format-exponent] is @racket[#f], the ``exponent marker'' is
@racket["e"] if @racket[base] is @racket[10] and a string involving @racket["e"] if @racket[base] is @racket[10] and a string involving
@racket[base] otherwise: @racket[base] otherwise:
@interaction[#:eval the-eval @examples[#:label #f #:eval the-eval
(~r 1234 #:notation 'exponential) (~r 1234 #:notation 'exponential)
(~r 1234 #:notation 'exponential #:base 8) (~r 1234 #:notation 'exponential #:base 8)
] ]
@ -390,7 +389,7 @@ If @racket[format-exponent] is @racket[#f], the ``exponent marker'' is
If @racket[format-exponent] is a procedure, it is applied to the exponent and If @racket[format-exponent] is a procedure, it is applied to the exponent and
the resulting string is appended to the significand: the resulting string is appended to the significand:
@interaction[#:eval the-eval @examples[#:label #f #:eval the-eval
(~r 1234 #:notation 'exponential (~r 1234 #:notation 'exponential
#:format-exponent (lambda (e) (format "E~a" e))) #:format-exponent (lambda (e) (format "E~a" e)))
]} ]}

View File

@ -2,7 +2,7 @@
@(require "mz.rkt" (for-label racket/future)) @(require "mz.rkt" (for-label racket/future))
@(define future-eval (make-base-eval)) @(define future-eval (make-base-eval))
@(interaction-eval #:eval future-eval (require racket/future)) @examples[#:hidden #:eval future-eval (require racket/future)]
@(define time-id @racketidfont{time}) @(define time-id @racketidfont{time})
@ -67,7 +67,7 @@ execute through a call to @racket[touch], however.
future, the given @racket[thunk] may run speculatively in parallel to future, the given @racket[thunk] may run speculatively in parallel to
other computations, as described above. other computations, as described above.
@interaction[ @examples[
#:eval future-eval #:eval future-eval
(let ([f (future (lambda () (+ 1 2)))]) (let ([f (future (lambda () (+ 1 2)))])
(list (+ 3 4) (touch f))) (list (+ 3 4) (touch f)))

View File

@ -132,7 +132,7 @@ method} called @racket[name] that does not support the @techlink{generic
instance} @racket[v]. instance} @racket[v].
@examples[#:eval evaluator @examples[#:eval evaluator
(raise-support-error 'some-method-name '("arbitrary" "instance" "value")) (eval:error (raise-support-error 'some-method-name '("arbitrary" "instance" "value")))
] ]
} }
@ -233,7 +233,7 @@ syntax error.}
make-num) make-num)
(define z (make-num-contracted 10)) (define z (make-num-contracted 10))
(gen-print* z #:width "not a number" #:height 5) (eval:error (gen-print* z #:width "not a number" #:height 5))
] ]
@defform[(generic-instance/c gen-id [method-id method-ctc] ...) @defform[(generic-instance/c gen-id [method-id method-ctc] ...)

View File

@ -546,7 +546,7 @@ key @racket[k] and value @racket[v], if a mapping from @racket[k] to some value
@racket[v0] already exists, it is replaced with a mapping from @racket[k] to @racket[v0] already exists, it is replaced with a mapping from @racket[k] to
@racket[(combine/key k v0 v)]. @racket[(combine/key k v0 v)].
@defexamples[ @examples[
#:eval the-eval #:eval the-eval
(hash-union (make-immutable-hash '([1 . one])) (hash-union (make-immutable-hash '([1 . one]))
(make-immutable-hash '([2 . two])) (make-immutable-hash '([2 . two]))
@ -574,7 +574,7 @@ key @racket[k] and value @racket[v], if a mapping from @racket[k] to some value
@racket[v0] already exists, it is replaced with a mapping from @racket[k] to @racket[v0] already exists, it is replaced with a mapping from @racket[k] to
@racket[(combine/key k v0 v)]. @racket[(combine/key k v0 v)].
@defexamples[ @examples[
#:eval the-eval #:eval the-eval
(define h (make-hash)) (define h (make-hash))
h h

View File

@ -324,8 +324,8 @@ argument list takes precedence.}
@note-lib[racket/logging] @note-lib[racket/logging]
@(require (for-label racket/logging)) @(require (for-label racket/logging))
@(define log-eval (make-base-eval)) @(define log-eval (make-base-eval))
@(interaction-eval #:eval log-eval @examples[#:hidden #:eval log-eval
(require racket/logging)) (require racket/logging)]
@defproc[(log-level/c [v any/c]) @defproc[(log-level/c [v any/c])
boolean?]{ boolean?]{
@ -353,7 +353,7 @@ Runs @racket[proc], calling @racket[interceptor] on any log event that would
be received by @racket[(make-log-receiver (current-logger) level topic ... ...)]. be received by @racket[(make-log-receiver (current-logger) level topic ... ...)].
Returns whatever @racket[proc] returns. Returns whatever @racket[proc] returns.
@defexamples[ @examples[
#:eval log-eval #:eval log-eval
(let ([warning-counter 0]) (let ([warning-counter 0])
(with-intercepted-logging (with-intercepted-logging
@ -381,7 +381,7 @@ Runs @racket[proc], outputting any logging that would be received by
@racket[(make-log-receiver (current-logger) level topic ... ...)] to @racket[port]. @racket[(make-log-receiver (current-logger) level topic ... ...)] to @racket[port].
Returns whatever @racket[proc] returns. Returns whatever @racket[proc] returns.
@defexamples[ @examples[
#:eval log-eval #:eval log-eval
(let ([my-log (open-output-string)]) (let ([my-log (open-output-string)])
(with-logging-to-port my-log (with-logging-to-port my-log

View File

@ -2,8 +2,8 @@
@(require "mz.rkt" "match-grammar.rkt" racket/match) @(require "mz.rkt" "match-grammar.rkt" racket/match)
@(define match-eval (make-base-eval)) @(define match-eval (make-base-eval))
@(interaction-eval #:eval match-eval (require racket/match racket/list)) @examples[#:hidden #:eval match-eval (require racket/match racket/list)]
@(interaction-eval #:eval match-eval (require (for-syntax racket/base))) @examples[#:hidden #:eval match-eval (require (for-syntax racket/base))]
@title[#:tag "match"]{Pattern Matching} @title[#:tag "match"]{Pattern Matching}
@ -239,9 +239,9 @@ In more detail, patterns match as follows:
@racket[struct] declaration can provide the structure type @racket[struct] declaration can provide the structure type
information. information.
@defexamples[ @examples[
#:eval match-eval #:eval match-eval
(define-struct tree (val left right)) (eval:no-prompt (define-struct tree (val left right)))
(match (make-tree 0 (make-tree 1 #f #f) #f) (match (make-tree 0 (make-tree 1 #f #f) #f)
[(tree a (tree b _ _) _) (list a b)]) [(tree a (tree b _ _) _) (list a b)])
]} ]}
@ -430,27 +430,30 @@ many values to expect from @racket[expr].
The arguments are ordered as they appear in the function header for The arguments are ordered as they appear in the function header for
matching purposes. matching purposes.
@defexamples[#:eval match-eval @examples[#:eval match-eval
(define/match (fact n) (eval:no-prompt
[(0) 1] (define/match (fact n)
[(n) (* n (fact (sub1 n)))]) [(0) 1]
[(n) (* n (fact (sub1 n)))]))
(fact 5) (fact 5)
] ]
The function header may also contain optional or keyword arguments, The function header may also contain optional or keyword arguments,
may have curried arguments, and may also contain a rest argument. may have curried arguments, and may also contain a rest argument.
@defexamples[#:eval match-eval @examples[#:eval match-eval
(define/match ((f x) #:y [y '(1 2 3)]) (eval:no-prompt
[((regexp #rx"p+") `(,a 2 3)) a] (define/match ((f x) #:y [y '(1 2 3)])
[(_ _) #f]) [((regexp #rx"p+") `(,a 2 3)) a]
[(_ _) #f]))
((f "ape") #:y '(5 2 3)) ((f "ape") #:y '(5 2 3))
((f "dog")) ((f "dog"))
(define/match (g x y . rst) (eval:no-prompt
[(0 0 '()) #t] (define/match (g x y . rst)
[(5 5 '(5 5)) #t] [(0 0 '()) #t]
[(_ _ _) #f]) [(5 5 '(5 5)) #t]
[(_ _ _) #f]))
(g 0 0) (g 0 0)
(g 5 5 5 5) (g 5 5 5 5)
(g 1 2) (g 1 2)
@ -586,9 +589,10 @@ are used as binding identifiers (like any other identifier) when they appear
anywhere except the first position in a sequence. anywhere except the first position in a sequence.
For example, to extend the pattern matcher and destructure syntax lists, For example, to extend the pattern matcher and destructure syntax lists,
@defs+int[ @examples[#:label #f
#:eval match-eval #:eval match-eval
((define (syntax-list? x) (eval:no-prompt
(define (syntax-list? x)
(and (syntax? x) (and (syntax? x)
(list? (syntax->list x)))) (list? (syntax->list x))))
(define-match-expander syntax-list (define-match-expander syntax-list
@ -602,8 +606,7 @@ For example, to extend the pattern matcher and destructure syntax lists,
(and (identifier? stx) (and (identifier? stx)
(free-identifier=? stx keyword)))) (free-identifier=? stx keyword))))
(define or-keyword? (make-keyword-predicate #'or)) (define or-keyword? (make-keyword-predicate #'or))
(define and-keyword? (make-keyword-predicate #'and)) (define and-keyword? (make-keyword-predicate #'and)))
)
(match #'(or 3 4) (match #'(or 3 4)
[(syntax-list (? or-keyword?) b c) [(syntax-list (? or-keyword?) b c)
@ -622,9 +625,10 @@ And here is an example showing how
@racket[define-match-expander]-bound identifiers are @racket[define-match-expander]-bound identifiers are
not treated specially unless they appear not treated specially unless they appear
in the first position of pattern sequence. in the first position of pattern sequence.
@defs+int[ @examples[#:label #f
#:eval match-eval #:eval match-eval
((define-match-expander nil (eval:no-prompt
(define-match-expander nil
(λ (stx) #''()) (λ (stx) #''())
(λ (stx) #''())) (λ (stx) #''()))
(define (len l) (define (len l)
@ -728,9 +732,10 @@ not provided, it defaults to @racket[equal?].
Any field of @racket[struct-id] may be omitted, and such fields can Any field of @racket[struct-id] may be omitted, and such fields can
occur in any order. occur in any order.
@defexamples[ @examples[
#:eval match-eval #:eval match-eval
(define-struct tree (val left right)) (eval:no-prompt
(define-struct tree (val left right)))
(match (make-tree 0 (make-tree 1 #f #f) #f) (match (make-tree 0 (make-tree 1 #f #f) #f)
[(struct* tree ([val a] [(struct* tree ([val a]
[left (struct* tree ([right #f] [val b]))])) [left (struct* tree ([right #f] [val b]))]))

View File

@ -2,13 +2,13 @@
(require scribble/struct (require scribble/struct
scribble/manual scribble/manual
scribble/eval scribble/examples
scribble/decode scribble/decode
racket/contract racket/contract
"../icons.rkt") "../icons.rkt")
(provide (all-from-out scribble/manual) (provide (all-from-out scribble/manual)
(all-from-out scribble/eval) (all-from-out scribble/examples)
(all-from-out racket/contract)) (all-from-out racket/contract))
(require (for-label racket)) (require (for-label racket))

View File

@ -8,7 +8,7 @@
racket/random)) racket/random))
@(define math-eval (make-base-eval)) @(define math-eval (make-base-eval))
@(interaction-eval #:eval math-eval (require racket/math)) @examples[#:hidden #:eval math-eval (require racket/math)]
@title[#:tag "numbers" #:style '(toc)]{Numbers} @title[#:tag "numbers" #:style '(toc)]{Numbers}
@ -193,12 +193,12 @@ number, @racket[#f] otherwise.}
@defproc[(even? [n integer?]) boolean?]{ Returns @racket[(zero? (modulo @defproc[(even? [n integer?]) boolean?]{ Returns @racket[(zero? (modulo
n 2))]. n 2))].
@mz-examples[(even? 10.0) (even? 11) (even? +inf.0)]} @mz-examples[(even? 10.0) (even? 11) (eval:error (even? +inf.0))]}
@defproc[(odd? [n integer?]) boolean?]{ Returns @racket[(not (even? n))]. @defproc[(odd? [n integer?]) boolean?]{ Returns @racket[(not (even? n))].
@mz-examples[(odd? 10.0) (odd? 11) (odd? +inf.0)]} @mz-examples[(odd? 10.0) (odd? 11) (eval:error (odd? +inf.0))]}
@defproc[(exact? [z number?]) boolean?]{ Returns @racket[#t] if @racket[z] @defproc[(exact? [z number?]) boolean?]{ Returns @racket[#t] if @racket[z]
@ -289,7 +289,7 @@ If @racket[z] is exact @racket[0] and no @racket[w] is exact
Returns @racket[(truncate (/ n m))]. Returns @racket[(truncate (/ n m))].
@mz-examples[(quotient 10 3) (quotient -10.0 3) (quotient +inf.0 3)]} @mz-examples[(quotient 10 3) (quotient -10.0 3) (eval:error (quotient +inf.0 3))]}
@defproc[(remainder [n integer?] [m integer?]) integer?]{ @defproc[(remainder [n integer?] [m integer?]) integer?]{
@ -307,7 +307,7 @@ Returns @racket[_q] with the same sign as @racket[n] such that
If @racket[m] is exact @racket[0], the If @racket[m] is exact @racket[0], the
@exnraise[exn:fail:contract:divide-by-zero]. @exnraise[exn:fail:contract:divide-by-zero].
@mz-examples[(remainder 10 3) (remainder -10.0 3) (remainder 10.0 -3) (remainder -10 -3) (remainder +inf.0 3)]} @mz-examples[(remainder 10 3) (remainder -10.0 3) (remainder 10.0 -3) (remainder -10 -3) (eval:error (remainder +inf.0 3))]}
@defproc[(quotient/remainder [n integer?] [m integer?]) (values integer? integer?)]{ @defproc[(quotient/remainder [n integer?] [m integer?]) (values integer? integer?)]{
@ -336,7 +336,7 @@ Returns @racket[_q] with the same sign as @racket[m] where
If @racket[m] is exact @racket[0], the If @racket[m] is exact @racket[0], the
@exnraise[exn:fail:contract:divide-by-zero]. @exnraise[exn:fail:contract:divide-by-zero].
@mz-examples[(modulo 10 3) (modulo -10.0 3) (modulo 10.0 -3) (modulo -10 -3) (modulo +inf.0 3)]} @mz-examples[(modulo 10 3) (modulo -10.0 3) (modulo 10.0 -3) (modulo -10 -3) (eval:error (modulo +inf.0 3))]}
@defproc[(add1 [z number?]) number?]{ Returns @racket[(+ z 1)].} @defproc[(add1 [z number?]) number?]{ Returns @racket[(+ z 1)].}

View File

@ -249,7 +249,8 @@ merely start with a chain of at least @racket[(add1 pos)] pairs.
(list-ref (list 'a 'b 'c) 0) (list-ref (list 'a 'b 'c) 0)
(list-ref (list 'a 'b 'c) 1) (list-ref (list 'a 'b 'c) 1)
(list-ref (list 'a 'b 'c) 2) (list-ref (list 'a 'b 'c) 2)
(list-ref (cons 1 2) 0)]} (list-ref (cons 1 2) 0)
(eval:error (list-ref (cons 1 2) 1))]}
@defproc[(list-tail [lst any/c] [pos exact-nonnegative-integer?]) @defproc[(list-tail [lst any/c] [pos exact-nonnegative-integer?])
@ -264,8 +265,9 @@ must merely start with a chain of at least @racket[pos] pairs.
@mz-examples[ @mz-examples[
(list-tail (list 1 2 3 4) 2) (list-tail (list 1 2 3 4) 2)
(list-ref (cons 1 2) 1) (list-tail (cons 1 2) 1)
(list-ref 'not-a-pair 0)]} (eval:error (list-tail (cons 1 2) 2))
(list-tail 'not-a-pair 0)]}
@defproc*[([(append [lst list?] ...) list?] @defproc*[([(append [lst list?] ...) list?]
@ -342,7 +344,7 @@ If the @racket[lst]s are empty, then @racket[#t] is returned.
@mz-examples[ @mz-examples[
(andmap positive? '(1 2 3)) (andmap positive? '(1 2 3))
(andmap positive? '(1 2 a)) (eval:error (andmap positive? '(1 2 a)))
(andmap positive? '(1 -2 a)) (andmap positive? '(1 -2 a))
(andmap + '(1 2 3) '(4 5 6))]} (andmap + '(1 2 3) '(4 5 6))]}
@ -711,8 +713,8 @@ Like @racket[assoc], but finds an element using the predicate
@note-lib[racket/list] @note-lib[racket/list]
@(define list-eval (make-base-eval)) @(define list-eval (make-base-eval))
@(interaction-eval #:eval list-eval @examples[#:hidden #:eval list-eval
(require racket/list (only-in racket/function negate))) (require racket/list (only-in racket/function negate))]
@defthing[empty null?]{ @defthing[empty null?]{
@ -1329,7 +1331,7 @@ Computes the n-ary cartesian product of the given lists.
Returns a list that is like @racket[lst], omitting the first element of @racket[lst] Returns a list that is like @racket[lst], omitting the first element of @racket[lst]
for which @racket[pred] produces a true value. for which @racket[pred] produces a true value.
@defexamples[ @examples[
#:eval list-eval #:eval list-eval
(remf negative? '(1 -2 3 4 -5)) (remf negative? '(1 -2 3 4 -5))
] ]
@ -1342,7 +1344,7 @@ for which @racket[pred] produces a true value.
Like @racket[remf], but removes all the elements for which @racket[pred] Like @racket[remf], but removes all the elements for which @racket[pred]
produces a true value. produces a true value.
@defexamples[ @examples[
#:eval list-eval #:eval list-eval
(remf* negative? '(1 -2 3 4 -5)) (remf* negative? '(1 -2 3 4 -5))
] ]

View File

@ -9,7 +9,7 @@
@section{Port String and List Conversions} @section{Port String and List Conversions}
@(define port-eval (make-base-eval)) @(define port-eval (make-base-eval))
@(interaction-eval #:eval port-eval (require racket/port)) @examples[#:hidden #:eval port-eval (require racket/port)]
@defproc[(port->list [r (input-port? . -> . any/c) read] [in input-port? (current-input-port)]) @defproc[(port->list [r (input-port? . -> . any/c) read] [in input-port? (current-input-port)])
(listof any/c)]{ (listof any/c)]{

View File

@ -123,9 +123,10 @@ not require any other keywords, and it must accept as many by-position
arguments as supplied via the @racket[v]s and @racket[lst]; otherwise, arguments as supplied via the @racket[v]s and @racket[lst]; otherwise,
the @exnraise[exn:fail:contract]. the @exnraise[exn:fail:contract].
@defexamples[ @examples[
(define (f x #:y y #:z [z 10]) (eval:no-prompt
(list x y z)) (define (f x #:y y #:z [z 10])
(list x y z)))
(keyword-apply f '(#:y) '(2) '(1)) (keyword-apply f '(#:y) '(2) '(1))
(keyword-apply f '(#:y #:z) '(2 3) '(1)) (keyword-apply f '(#:y #:z) '(2 3) '(1))
(keyword-apply f #:z 7 '(#:y) '(2) '(1)) (keyword-apply f #:z 7 '(#:y) '(2) '(1))
@ -207,7 +208,7 @@ arity-reduced procedure) or @racket[arity] must be the empty list
@examples[ @examples[
(define my+ (procedure-reduce-arity + 2)) (define my+ (procedure-reduce-arity + 2))
(my+ 1 2) (my+ 1 2)
(my+ 1 2 3) (eval:error (my+ 1 2 3))
]} ]}
@defproc[(procedure-keywords [proc procedure?]) @defproc[(procedure-keywords [proc procedure?])
@ -256,19 +257,21 @@ The result of @racket[procedure-arity] and @racket[object-name] on the
new procedure is the same as for @racket[plain-proc]. See also new procedure is the same as for @racket[plain-proc]. See also
@racket[procedure-reduce-keyword-arity] and @racket[procedure-rename]. @racket[procedure-reduce-keyword-arity] and @racket[procedure-rename].
@defexamples[ @examples[
(define show (eval:no-prompt
(make-keyword-procedure (lambda (kws kw-args . rest) (define show
(list kws kw-args rest)))) (make-keyword-procedure (lambda (kws kw-args . rest)
(list kws kw-args rest)))))
(show 1) (show 1)
(show #:init 0 1 2 3 #:extra 4) (show #:init 0 1 2 3 #:extra 4)
(define show2 (eval:no-prompt
(make-keyword-procedure (lambda (kws kw-args . rest) (define show2
(list kws kw-args rest)) (make-keyword-procedure (lambda (kws kw-args . rest)
(lambda args (list kws kw-args rest))
(list->vector args)))) (lambda args
(list->vector args)))))
(show2 1) (show2 1)
(show2 #:init 0 1 2 3 #:extra 4) (show2 #:init 0 1 2 3 #:extra 4)
]} ]}
@ -291,15 +294,16 @@ must require no more keywords than the ones listed in
@racket[allowed-kws] (or it must allow all keywords if @racket[allowed-kws] (or it must allow all keywords if
@racket[allowed-kws] is @racket[#f]). @racket[allowed-kws] is @racket[#f]).
@defexamples[ @examples[
(define orig-show (eval:no-prompt
(make-keyword-procedure (lambda (kws kw-args . rest) (define orig-show
(list kws kw-args rest)))) (make-keyword-procedure (lambda (kws kw-args . rest)
(define show (procedure-reduce-keyword-arity (list kws kw-args rest))))
orig-show 3 '(#:init) '(#:extra #:init))) (define show (procedure-reduce-keyword-arity
orig-show 3 '(#:init) '(#:extra #:init))))
(show #:init 0 1 2 3 #:extra 4) (show #:init 0 1 2 3 #:extra 4)
(show 1) (eval:error (show 1))
(show #:init 0 1 2 3 #:extra 4 #:more 7) (eval:error (show #:init 0 1 2 3 #:extra 4 #:more 7))
]} ]}
@defstruct[arity-at-least ([value exact-nonnegative-integer?])]{ @defstruct[arity-at-least ([value exact-nonnegative-integer?])]{
@ -452,7 +456,7 @@ property is not associated with a procedure structure type.
(apply pairs more))]))) (apply pairs more))])))
(pairs 1 2 3 4) (pairs 1 2 3 4)
(pairs 5)]} (eval:error (pairs 5))]}
@defthing[prop:checked-procedure struct-type-property?]{ @defthing[prop:checked-procedure struct-type-property?]{
@ -517,7 +521,7 @@ applied.}
@note-lib[racket/function] @note-lib[racket/function]
@(define fun-eval (make-base-eval)) @(define fun-eval (make-base-eval))
@(interaction-eval #:eval fun-eval (require racket/function)) @examples[#:hidden #:eval fun-eval (require racket/function)]
@defproc[(identity [v any/c]) any/c]{ @defproc[(identity [v any/c]) any/c]{
Returns @racket[v]. Returns @racket[v].
@ -540,13 +544,15 @@ The @racket[thunk] form creates a nullary function that evaluates the
given body. The @racket[thunk*] form is similar, except that the given body. The @racket[thunk*] form is similar, except that the
resulting function accepts any arguments (including keyword arguments). resulting function accepts any arguments (including keyword arguments).
@defexamples[ @examples[
#:eval fun-eval #:eval fun-eval
(define th1 (thunk (define x 1) (printf "~a\n" x))) (eval:no-prompt
(define th1 (thunk (define x 1) (printf "~a\n" x))))
(th1) (th1)
(th1 'x) (eval:error (th1 'x))
(th1 #:y 'z) (eval:error (th1 #:y 'z))
(define th2 (thunk* (define x 1) (printf "~a\n" x))) (eval:no-prompt
(define th2 (thunk* (define x 1) (printf "~a\n" x))))
(th2) (th2)
(th2 'x) (th2 'x)
(th2 #:y 'z) (th2 #:y 'z)
@ -567,9 +573,10 @@ returns the @racket[not] of @racket[proc]'s result.
Combines calls to each function with @racket[and]. Equivalent to Combines calls to each function with @racket[and]. Equivalent to
@racket[(and (f x ...) ...)] @racket[(and (f x ...) ...)]
@defexamples[ @examples[
#:eval fun-eval #:eval fun-eval
(define f (conjoin exact? integer?)) (eval:no-prompt
(define f (conjoin exact? integer?)))
(f 1) (f 1)
(f 1.0) (f 1.0)
(f 1/2) (f 1/2)
@ -583,9 +590,10 @@ Combines calls to each function with @racket[and]. Equivalent to
Combines calls to each function with @racket[or]. Equivalent to Combines calls to each function with @racket[or]. Equivalent to
@racket[(or (f x ...) ...)] @racket[(or (f x ...) ...)]
@defexamples[ @examples[
#:eval fun-eval #:eval fun-eval
(define f (disjoin exact? integer?)) (eval:no-prompt
(define f (disjoin exact? integer?)))
(f 1) (f 1)
(f 1.0) (f 1.0)
(f 1/2) (f 1/2)

View File

@ -240,7 +240,7 @@ returns the source byte string for a @tech{regexp value}.
@examples[ @examples[
(byte-regexp #"ap*le") (byte-regexp #"ap*le")
(object-name #rx#"ap*le") (object-name #rx#"ap*le")
(byte-regexp "ap*le") (eval:error (byte-regexp "ap*le"))
]} ]}
@defproc[(byte-pregexp [bstr bytes?]) byte-pregexp?]{ @defproc[(byte-pregexp [bstr bytes?]) byte-pregexp?]{

View File

@ -6,7 +6,7 @@
racket/gui/dynamic)) racket/gui/dynamic))
@(define box-eval (make-base-eval)) @(define box-eval (make-base-eval))
@(interaction-eval #:eval box-eval (require racket/sandbox)) @examples[#:hidden #:eval box-eval (require racket/sandbox)]
@title{Sandboxed Evaluation} @title{Sandboxed Evaluation}
@ -147,11 +147,12 @@ The following examples illustrate the difference between an evaluator
that puts the program in a module and one that merely initializes a that puts the program in a module and one that merely initializes a
top-level namespace: top-level namespace:
@interaction[ @examples[#:label #f
#:eval box-eval #:eval box-eval
(define base-module-eval (eval:error
(code:comment @#,t{a module cannot have free variables...}) (define base-module-eval
(make-evaluator 'racket/base '(define (f) later))) (code:comment @#,t{a module cannot have free variables...})
(make-evaluator 'racket/base '(define (f) later))))
(define base-module-eval (define base-module-eval
(make-evaluator 'racket/base '(define (f) later) (make-evaluator 'racket/base '(define (f) later)
'(define later 5))) '(define later 5)))
@ -229,9 +230,10 @@ of communication makes it impossible to have nested (or concurrent)
calls to a single evaluator. Usually this is not a problem, but in calls to a single evaluator. Usually this is not a problem, but in
some cases you can get the evaluator function available inside the some cases you can get the evaluator function available inside the
sandboxed code, for example: sandboxed code, for example:
@interaction[#:eval box-eval @examples[#:label #f #:eval box-eval
(let ([e (make-evaluator 'racket/base)]) (eval:error
(e `(,e 1))) (let ([e (make-evaluator 'racket/base)])
(e `(,e 1))))
] ]
An error will be signaled in such cases. An error will be signaled in such cases.

View File

@ -26,7 +26,7 @@ vice-versa.
@(define sequence-evaluator @(define sequence-evaluator
(let ([evaluator (make-base-eval)]) (let ([evaluator (make-base-eval)])
(evaluator '(require racket/generic racket/list racket/stream racket/sequence (evaluator '(require racket/generic racket/list racket/stream racket/sequence
racket/contract)) racket/contract racket/dict))
evaluator)) evaluator))
@guideintro["sequences"]{sequences} @guideintro["sequences"]{sequences}
@ -152,7 +152,7 @@ each element in the sequence.
Returns @racket[#t] if @racket[v] can be used as a @tech{sequence}, Returns @racket[#t] if @racket[v] can be used as a @tech{sequence},
@racket[#f] otherwise. @racket[#f] otherwise.
@interaction[#:eval sequence-evaluator @examples[#:eval sequence-evaluator
(sequence? 42) (sequence? 42)
(sequence? '(a b c)) (sequence? '(a b c))
(sequence? "word") (sequence? "word")
@ -169,12 +169,12 @@ each element in the sequence.
@racket[step] is non-negative, or less or equal to @racket[end] if @racket[step] is non-negative, or less or equal to @racket[end] if
@racket[step] is negative. @speed[in-range "number"] @racket[step] is negative. @speed[in-range "number"]
Example: gaussian sum
@interaction[#:eval sequence-evaluator @examples[#:label "Example: gaussian sum" #:eval sequence-evaluator
(for/sum ([x (in-range 10)]) x)] (for/sum ([x (in-range 10)]) x)]
Example: sum of even numbers
@interaction[#:eval sequence-evaluator @examples[#:label "Example: sum of even numbers" #:eval sequence-evaluator
(for/sum ([x (in-range 0 100 2)]) x)] (for/sum ([x (in-range 0 100 2)]) x)]
} }
@ -184,7 +184,7 @@ each element in the sequence.
integers starting with @racket[start], where each element is one integers starting with @racket[start], where each element is one
more than the preceding element. @speed[in-naturals "integer"] more than the preceding element. @speed[in-naturals "integer"]
@interaction[#:eval sequence-evaluator @examples[#:eval sequence-evaluator
(for/list ([k (in-naturals)] (for/list ([k (in-naturals)]
[x (in-range 10)]) [x (in-range 10)])
(list k x))] (list k x))]
@ -197,7 +197,7 @@ each element in the sequence.
@info-on-seq["pairs" "lists"] @info-on-seq["pairs" "lists"]
@speed[in-list "list"] @speed[in-list "list"]
@interaction[#:eval sequence-evaluator @examples[#:eval sequence-evaluator
(for/list ([x (in-list '(3 1 4))]) (for/list ([x (in-list '(3 1 4))])
`(,x ,(* x x)))] `(,x ,(* x x)))]
} }
@ -207,7 +207,7 @@ each element in the sequence.
@info-on-seq["mpairs" "mutable lists"] @info-on-seq["mpairs" "mutable lists"]
@speed[in-mlist "mutable list"] @speed[in-mlist "mutable list"]
@interaction[#:eval sequence-evaluator @examples[#:eval sequence-evaluator
(for/list ([x (in-mlist (mcons "RACKET" (mcons "LANG" '())))]) (for/list ([x (in-mlist (mcons "RACKET" (mcons "LANG" '())))])
(string-length x))] (string-length x))]
} }
@ -242,7 +242,7 @@ each element in the sequence.
@speed[in-vector "vector"] @speed[in-vector "vector"]
@interaction[#:eval sequence-evaluator @examples[#:eval sequence-evaluator
(define (histogram vector-of-words) (define (histogram vector-of-words)
(define a-hash (make-hash)) (define a-hash (make-hash))
(for ([word (in-vector vector-of-words)]) (for ([word (in-vector vector-of-words)])
@ -266,7 +266,7 @@ each element in the sequence.
@speed[in-string "string"] @speed[in-string "string"]
@interaction[#:eval sequence-evaluator @examples[#:eval sequence-evaluator
(define (line-count str) (define (line-count str)
(for/sum ([ch (in-string str)]) (for/sum ([ch (in-string str)])
(if (char=? #\newline ch) 1 0))) (if (char=? #\newline ch) 1 0)))
@ -288,7 +288,7 @@ each element in the sequence.
@speed[in-bytes "byte string"] @speed[in-bytes "byte string"]
@interaction[#:eval sequence-evaluator @examples[#:eval sequence-evaluator
(define (has-eof? bs) (define (has-eof? bs)
(for/or ([ch (in-bytes bs)]) (for/or ([ch (in-bytes bs)])
(= ch 0))) (= ch 0)))
@ -797,27 +797,30 @@ for instance, a wrapped list is not guaranteed to satisfy @racket[list?].
If @racket[min-count] is a number, the stream is required to have at least that many elements in it. If @racket[min-count] is a number, the stream is required to have at least that many elements in it.
@defexamples[ @examples[
#:eval sequence-evaluator #:eval sequence-evaluator
(define/contract predicates (define/contract predicates
(sequence/c (-> any/c boolean?)) (sequence/c (-> any/c boolean?))
(in-list (list integer? (in-list (list integer?
string->symbol))) string->symbol)))
(for ([P predicates]) (eval:error
(printf "~s\n" (P "cat"))) (for ([P predicates])
(printf "~s\n" (P "cat"))))
(define/contract numbers&strings (define/contract numbers&strings
(sequence/c number? string?) (sequence/c number? string?)
(in-dict (list (cons 1 "one") (in-dict (list (cons 1 "one")
(cons 2 "two") (cons 2 "two")
(cons 3 'three)))) (cons 3 'three))))
(for ([(N S) numbers&strings]) (eval:error
(printf "~s: ~a\n" N S)) (for ([(N S) numbers&strings])
(printf "~s: ~a\n" N S)))
(define/contract a-sequence (define/contract a-sequence
(sequence/c #:min-count 2 char?) (sequence/c #:min-count 2 char?)
"x") "x")
(for ([x a-sequence] (eval:error
[i (in-naturals)]) (for ([x a-sequence]
(printf "~a is ~a\n" i x)) [i (in-naturals)])
(printf "~a is ~a\n" i x)))
] ]
} }
@ -1202,11 +1205,12 @@ values from the generator.
literal, exact, non-negative integer. literal, exact, non-negative integer.
@examples[#:eval generator-eval @examples[#:eval generator-eval
(let ([g (in-generator (eval:error
(let loop ([n 3]) (let ([g (in-generator
(unless (zero? n) (yield n (add1 n)) (loop (sub1 n)))))]) (let loop ([n 3])
(let-values ([(not-empty? next) (sequence-generate g)]) (unless (zero? n) (yield n (add1 n)) (loop (sub1 n)))))])
(let loop () (when (not-empty?) (next) (loop))) 'done)) (let-values ([(not-empty? next) (sequence-generate g)])
(let loop () (when (not-empty?) (next) (loop))) 'done)))
(let ([g (in-generator #:arity 2 (let ([g (in-generator #:arity 2
(let loop ([n 3]) (let loop ([n 3])
(unless (zero? n) (yield n (add1 n)) (loop (sub1 n)))))]) (unless (zero? n) (yield n (add1 n)) (loop (sub1 n)))))])
@ -1216,7 +1220,7 @@ values from the generator.
To use an existing generator as a sequence, use @racket[in-producer] To use an existing generator as a sequence, use @racket[in-producer]
with a stop-value known for the generator: with a stop-value known for the generator:
@interaction[#:eval generator-eval @examples[#:label #f #:eval generator-eval
(define abc-generator (generator () (define abc-generator (generator ()
(for ([x '(a b c)]) (for ([x '(a b c)])
(yield x)))) (yield x))))

View File

@ -2,7 +2,7 @@
@(require "mz.rkt" racket/serialize (for-label racket/serialize racket/fasl)) @(require "mz.rkt" racket/serialize (for-label racket/serialize racket/fasl))
@(define ser-eval (make-base-eval)) @(define ser-eval (make-base-eval))
@(interaction-eval #:eval ser-eval (require racket/serialize)) @examples[#:hidden #:eval ser-eval (require racket/serialize)]
@title[#:tag "serialization"]{Serialization} @title[#:tag "serialization"]{Serialization}

View File

@ -3,7 +3,7 @@
@title[#:tag "sets"]{Sets} @title[#:tag "sets"]{Sets}
@(define set-eval (make-base-eval)) @(define set-eval (make-base-eval))
@(interaction-eval #:eval set-eval (require racket/set)) @examples[#:hidden #:eval set-eval (require racket/set)]
A @deftech{set} represents a collection of distinct elements. The following A @deftech{set} represents a collection of distinct elements. The following
datatypes are all sets: datatypes are all sets:
@ -446,7 +446,7 @@ Supported for any @racket[st] that @impl{implements} @racket[set-add] and @supp
(set-union (seteq)) (set-union (seteq))
(set-union (set 1 2) (set 2 3)) (set-union (set 1 2) (set 2 3))
(set-union (list 1 2) (list 2 3)) (set-union (list 1 2) (list 2 3))
(set-union (set 1 2) (seteq 2 3)) (code:comment "Sets of different types cannot be unioned.") (eval:error (set-union (set 1 2) (seteq 2 3))) (code:comment "Sets of different types cannot be unioned")
]} ]}
@defproc[(set-union! [st0 generic-set?] [st generic-set?] ...) void?]{ @defproc[(set-union! [st0 generic-set?] [st generic-set?] ...) void?]{
@ -598,8 +598,7 @@ Supported for any @racket[st] and @racket[st2] that both @supp{support}
(set=? (set 1 2 3) (set 1)) (set=? (set 1 2 3) (set 1))
(set=? (set 1 2 3) (set 1 2 3)) (set=? (set 1 2 3) (set 1 2 3))
(set=? (seteq 1 2) (mutable-seteq 2 1)) (set=? (seteq 1 2) (mutable-seteq 2 1))
(set=? (seteq 1 2) (seteqv 1 2)) (code:comment "Sets of different types cannot (eval:error (set=? (seteq 1 2) (seteqv 1 2))) (code:comment "Sets of different types cannot be compared")
be compared.")
] ]
} }

View File

@ -3,7 +3,7 @@
@(define shared-eval (make-base-eval)) @(define shared-eval (make-base-eval))
@(interaction-eval #:eval shared-eval (require racket/shared)) @examples[#:hidden #:eval shared-eval (require racket/shared)]
@(define maker @(define maker
(make-element #f (list (make-element #f (list
@ -125,11 +125,11 @@ that can be created via mutation).
(shared ([a (cons 1 b)] (shared ([a (cons 1 b)]
[b 7]) [b 7])
a) a)
(shared ([a a]) (code:comment @#,t{no indirection...}) (eval:error (shared ([a a]) (code:comment @#,t{no indirection...})
a) a))
(shared ([a (cons 1 b)] (code:comment @#,t{@racket[b] is early...}) (eval:error (shared ([a (cons 1 b)] (code:comment @#,t{@racket[b] is early...})
[b a]) [b a])
a) a))
(shared ([a (mcons 1 b)] (code:comment @#,t{@racket[b] is patchable...}) (shared ([a (mcons 1 b)] (code:comment @#,t{@racket[b] is patchable...})
[b a]) [b a])
a) a)

View File

@ -2,9 +2,9 @@
@(require "mz.rkt" (for-label racket/splicing racket/stxparam racket/local)) @(require "mz.rkt" (for-label racket/splicing racket/stxparam racket/local))
@(define splice-eval (make-base-eval)) @(define splice-eval (make-base-eval))
@interaction-eval[#:eval splice-eval (require racket/splicing @examples[#:hidden #:eval splice-eval (require racket/splicing
racket/stxparam racket/stxparam
(for-syntax racket/base))] (for-syntax racket/base))]
@title[#:tag "splicing"]{Local Binding with Splicing Body} @title[#:tag "splicing"]{Local Binding with Splicing Body}
@ -35,7 +35,7 @@ definition context (in the same way as for @racket[begin]).
(splicing-let-syntax ([one (lambda (stx) #'1)]) (splicing-let-syntax ([one (lambda (stx) #'1)])
(define o one)) (define o one))
o o
one (eval:error one)
] ]
When a splicing binding form occurs in a @tech{top-level context} or When a splicing binding form occurs in a @tech{top-level context} or
@ -46,9 +46,10 @@ once during compilation as in @racket[let-syntax], etc.
@examples[ @examples[
#:eval splice-eval #:eval splice-eval
(splicing-letrec ([x bad] (eval:error
[bad 1]) (splicing-letrec ([x bad]
x)] [bad 1])
x))]
If a definition within a splicing form is intended to be local to the If a definition within a splicing form is intended to be local to the
splicing body, then the identifier should have a true value for the splicing body, then the identifier should have a true value for the

View File

@ -2,7 +2,7 @@
@(require "mz.rkt") @(require "mz.rkt")
@(define sp-eval (make-base-eval)) @(define sp-eval (make-base-eval))
@(interaction-eval #:eval sp-eval (require racket/list)) @examples[#:hidden #:eval sp-eval (require racket/list)]
@title[#:tag "stringport"]{String Ports} @title[#:tag "stringport"]{String Ports}

View File

@ -378,7 +378,7 @@ allocated string).}
@note-lib[racket/string] @note-lib[racket/string]
@(define string-eval (make-base-eval)) @(define string-eval (make-base-eval))
@(interaction-eval #:eval string-eval (require racket/string racket/list)) @examples[#:hidden #:eval string-eval (require racket/string racket/list)]
@defproc[(string-append* [str string?] ... [strs (listof string?)]) string?]{ @defproc[(string-append* [str string?] ... [strs (listof string?)]) string?]{
@; Note: this is exactly the same description as the one for append* @; Note: this is exactly the same description as the one for append*

View File

@ -197,52 +197,52 @@ The result of @racket[make-struct-type] is five values:
@examples[ @examples[
#:eval struct-eval #:eval struct-eval
(define-values (struct:a make-a a? a-ref a-set!)
(make-struct-type 'a #f 2 1 'uninitialized)) (eval:no-prompt
(define an-a (make-a 'x 'y)) (define-values (struct:a make-a a? a-ref a-set!)
(make-struct-type 'a #f 2 1 'uninitialized))
(define an-a (make-a 'x 'y)))
(a-ref an-a 1) (a-ref an-a 1)
(a-ref an-a 2) (a-ref an-a 2)
(define a-first (make-struct-field-accessor a-ref 0)) (define a-first (make-struct-field-accessor a-ref 0))
(a-first an-a) (a-first an-a)
]
@interaction[ (eval:no-prompt
#:eval struct-eval (define-values (struct:b make-b b? b-ref b-set!)
(define-values (struct:b make-b b? b-ref b-set!) (make-struct-type 'b struct:a 1 2 'b-uninitialized))
(make-struct-type 'b struct:a 1 2 'b-uninitialized)) (define a-b (make-b 'x 'y 'z)))
(define a-b (make-b 'x 'y 'z))
(a-ref a-b 1) (a-ref a-b 1)
(a-ref a-b 2) (a-ref a-b 2)
(b-ref a-b 0) (b-ref a-b 0)
(b-ref a-b 1) (b-ref a-b 1)
(b-ref a-b 2) (b-ref a-b 2)
]
@interaction[ (eval:no-prompt
#:eval struct-eval (define-values (struct:c make-c c? c-ref c-set!)
(define-values (struct:c make-c c? c-ref c-set!) (make-struct-type
(make-struct-type 'c struct:b 0 0 #f null (make-inspector) #f null
'c struct:b 0 0 #f null (make-inspector) #f null (code:comment #,(t "guard checks for a number, and makes it inexact"))
(code:comment #,(t "guard checks for a number, and makes it inexact")) (lambda (a1 a2 b1 name)
(lambda (a1 a2 b1 name) (unless (number? a2)
(unless (number? a2) (error (string->symbol (format "make-~a" name))
(error (string->symbol (format "make-~a" name)) "second field must be a number"))
"second field must be a number")) (values a1 (exact->inexact a2) b1)))))
(values a1 (exact->inexact a2) b1))))
(make-c 'x 'y 'z) (eval:error (make-c 'x 'y 'z))
(define a-c (make-c 'x 2 'z)) (define a-c (make-c 'x 2 'z))
(a-ref a-c 1) (a-ref a-c 1)
]}
@interaction[ (eval:no-prompt
#:eval struct-eval (define p1 #s(p a b c))
(define p1 #s(p a b c)) (define-values (struct:p make-p p? p-ref p-set!)
(define-values (struct:p make-p p? p-ref p-set!) (make-struct-type 'p #f 3 0 #f null 'prefab #f '(0 1 2))))
(make-struct-type 'p #f 3 0 #f null 'prefab #f '(0 1 2)))
(p? p1) (p? p1)
(p-ref p1 0) (p-ref p1 0)
(make-p 'x 'y 'z) (make-p 'x 'y 'z)
] ]}
@defproc[(make-struct-field-accessor [accessor-proc struct-accessor-procedure?] @defproc[(make-struct-field-accessor [accessor-proc struct-accessor-procedure?]
[field-pos exact-nonnegative-integer?] [field-pos exact-nonnegative-integer?]
@ -667,7 +667,7 @@ the inaccessible fields are omitted from the list.
(struct->list (make-open 'a 'b)) (struct->list (make-open 'a 'b))
(struct->list #s(pre 1 2 3)) (struct->list #s(pre 1 2 3))
(define-struct (secret open) (x y)) (define-struct (secret open) (x y))
(struct->list (make-secret 0 1 17 22)) (eval:error (struct->list (make-secret 0 1 17 22)))
(struct->list (make-secret 0 1 17 22) #:on-opaque 'return-false) (struct->list (make-secret 0 1 17 22) #:on-opaque 'return-false)
(struct->list (make-secret 0 1 17 22) #:on-opaque 'skip) (struct->list (make-secret 0 1 17 22) #:on-opaque 'skip)
(struct->list 'not-a-struct #:on-opaque 'return-false) (struct->list 'not-a-struct #:on-opaque 'return-false)

View File

@ -2,7 +2,7 @@
@(require "mz.rkt") @(require "mz.rkt")
@(define stx-eval (make-base-eval)) @(define stx-eval (make-base-eval))
@(interaction-eval #:eval stx-eval (require (for-syntax racket/base))) @examples[#:hidden #:eval stx-eval (require (for-syntax racket/base))]
@title[#:tag "stxcmp"]{Syntax Object Bindings} @title[#:tag "stxcmp"]{Syntax Object Bindings}

View File

@ -1,5 +1,5 @@
#lang scribble/doc #lang scribble/doc
@(require "mz.rkt" scribble/eval) @(require "mz.rkt")
@(define stx-eval (make-base-eval)) @(define stx-eval (make-base-eval))
@(stx-eval '(require (for-syntax racket/base))) @(stx-eval '(require (for-syntax racket/base)))

View File

@ -1,6 +1,5 @@
#lang scribble/doc #lang scribble/doc
@(require "mz.rkt" @(require "mz.rkt"
scribble/eval
(for-label racket/stxparam racket/stxparam-exptime racket/splicing)) (for-label racket/stxparam racket/stxparam-exptime racket/splicing))
@(define the-eval (make-base-eval)) @(define the-eval (make-base-eval))
@ -30,7 +29,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 @racket[syntax-local-value] of @racket[id] does not produce
the target's value. the target's value.
@defexamples[#:eval the-eval @examples[#:eval the-eval
(define-syntax-parameter current-class #f) (define-syntax-parameter current-class #f)
(define-syntax-parameter yield (make-rename-transformer #'abort)) (define-syntax-parameter yield (make-rename-transformer #'abort))
(define-syntax-parameter define/public (define-syntax-parameter define/public
@ -59,7 +58,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 @racket[syntax-local-value] of @racket[id] does not produce
the target's value. the target's value.
@defexamples[#:eval the-eval @examples[#:eval the-eval
(define-syntax-parameter abort (syntax-rules ())) (define-syntax-parameter abort (syntax-rules ()))
(define-syntax forever (define-syntax forever

View File

@ -9,7 +9,7 @@
syntax/intdef)) syntax/intdef))
@(define stx-eval (make-base-eval)) @(define stx-eval (make-base-eval))
@(interaction-eval #:eval stx-eval (require (for-syntax racket/base))) @examples[#:hidden #:eval stx-eval (require (for-syntax racket/base))]
@(define (transform-time) @t{This procedure must be called during the @(define (transform-time) @t{This procedure must be called during the
dynamic extent of a @tech{syntax transformer} application by the dynamic extent of a @tech{syntax transformer} application by the
@ -592,7 +592,7 @@ if not @racket[#f]. If @racket[failure-thunk] is @racket[false], the
@examples[#:eval stx-eval @examples[#:eval stx-eval
(define-syntax (transformer-2 stx) (define-syntax (transformer-2 stx)
(syntax-local-value #'something-else (λ () (error "no binding")))) (syntax-local-value #'something-else (λ () (error "no binding"))))
(transformer-2) (eval:error (transformer-2))
] ]
@examples[#:eval stx-eval @examples[#:eval stx-eval
(define-syntax nachos #'(printf "nachos~n")) (define-syntax nachos #'(printf "nachos~n"))

View File

@ -2,7 +2,7 @@
@(require scribble/struct "mz.rkt" (for-syntax mzscheme)) @(require scribble/struct "mz.rkt" (for-syntax mzscheme))
@(define racket-eval (make-base-eval)) @(define racket-eval (make-base-eval))
@(interaction-eval #:eval racket-eval (require (for-syntax racket/base))) @examples[#:hidden #:eval racket-eval (require (for-syntax racket/base))]
@;------------------------------------------------------------------------ @;------------------------------------------------------------------------
@title[#:tag "syntax-model"]{Syntax Model} @title[#:tag "syntax-model"]{Syntax Model}
@ -893,7 +893,7 @@ bucket-2
(define (odd x) (if (zero? x) #f (even (sub1 x)))) (define (odd x) (if (zero? x) #f (even (sub1 x))))
(define (even x) (if (zero? x) #t (odd (sub1 x)))) (define (even x) (if (zero? x) #t (odd (sub1 x))))
(odd 17))])) (odd 17))]))
(defs-and-uses/fail) (eval:error (defs-and-uses/fail))
(define-syntax defs-and-uses (define-syntax defs-and-uses
(syntax-rules () (syntax-rules ()

View File

@ -36,13 +36,13 @@ in the argument list are automatically converted to symbols.
[(make-pred name) [(make-pred name)
(format-id #'name "~a?" (syntax-e #'name))])) (format-id #'name "~a?" (syntax-e #'name))]))
(make-pred pair) (make-pred pair)
(make-pred none-such) (eval:error (make-pred none-such))
(define-syntax (better-make-pred stx) (define-syntax (better-make-pred stx)
(syntax-case stx () (syntax-case stx ()
[(better-make-pred name) [(better-make-pred name)
(format-id #'name #:source #'name (format-id #'name #:source #'name
"~a?" (syntax-e #'name))])) "~a?" (syntax-e #'name))]))
(better-make-pred none-such) (eval:error (better-make-pred none-such))
] ]
(Scribble doesn't show it, but the DrRacket pinpoints the location of (Scribble doesn't show it, but the DrRacket pinpoints the location of
@ -108,9 +108,10 @@ is prefixed with the special form name as described under
@racket[current-syntax-context]. @racket[current-syntax-context].
@examples[#:eval the-eval @examples[#:eval the-eval
(wrong-syntax #'here "expected ~s" 'there) (eval:error (wrong-syntax #'here "expected ~s" 'there))
(parameterize ([current-syntax-context #'(look over here)]) (eval:error
(wrong-syntax #'here "expected ~s" 'there)) (parameterize ([current-syntax-context #'(look over here)])
(wrong-syntax #'here "expected ~s" 'there)))
] ]
A macro using @racket[wrong-syntax] might set the syntax context at the very A macro using @racket[wrong-syntax] might set the syntax context at the very

View File

@ -282,7 +282,7 @@ form. See also @racket[module-compiled-language-info],
See also @secref["module-eval-model"] and @secref["mod-parse"]. See also @secref["module-eval-model"] and @secref["mod-parse"].
@defexamples[#:eval (syntax-eval) @examples[#:eval (syntax-eval) #:once
(module duck racket/base (module duck racket/base
(provide num-eggs quack) (provide num-eggs quack)
(define num-eggs 2) (define num-eggs 2)
@ -510,13 +510,13 @@ bindings of each @racket[require-spec] are visible for expanding later
is not in the set that @racket[require-spec] describes, a syntax is not in the set that @racket[require-spec] describes, a syntax
error is reported. error is reported.
@defexamples[#:eval (syntax-eval) @examples[#:eval (syntax-eval) #:once
(require (only-in racket/tcp (require (only-in racket/tcp
tcp-listen tcp-listen
[tcp-accept my-accept])) [tcp-accept my-accept]))
tcp-listen tcp-listen
my-accept my-accept
tcp-accept (eval:error tcp-accept)
]} ]}
@defsubform[(except-in require-spec id ...)]{ Like @defsubform[(except-in require-spec id ...)]{ Like
@ -525,11 +525,11 @@ bindings of each @racket[require-spec] are visible for expanding later
in the set that @racket[require-spec] describes, a syntax error is in the set that @racket[require-spec] describes, a syntax error is
reported. reported.
@defexamples[#:eval (syntax-eval) @examples[#:eval (syntax-eval) #:once
(require (except-in racket/tcp (require (except-in racket/tcp
tcp-listen)) tcp-listen))
tcp-accept tcp-accept
tcp-listen (eval:error tcp-listen)
]} ]}
@defsubform[(prefix-in prefix-id require-spec)]{ Like @defsubform[(prefix-in prefix-id require-spec)]{ Like
@ -538,7 +538,7 @@ bindings of each @racket[require-spec] are visible for expanding later
@racket[prefix-id] is ignored, and instead preserved from the @racket[prefix-id] is ignored, and instead preserved from the
identifiers before prefixing. identifiers before prefixing.
@defexamples[#:eval (syntax-eval) @examples[#:eval (syntax-eval) #:once
(require (prefix-in tcp: racket/tcp)) (require (prefix-in tcp: racket/tcp))
tcp:tcp-accept tcp:tcp-accept
tcp:tcp-listen tcp:tcp-listen
@ -550,7 +550,7 @@ bindings of each @racket[require-spec] are visible for expanding later
@racket[orig-id] is not in the set that @racket[require-spec] @racket[orig-id] is not in the set that @racket[require-spec]
describes, a syntax error is reported. describes, a syntax error is reported.
@defexamples[#:eval (syntax-eval) @examples[#:eval (syntax-eval) #:once
(require (rename-in racket/tcp (require (rename-in racket/tcp
(tcp-accept accept) (tcp-accept accept)
(tcp-listen listen))) (tcp-listen listen)))
@ -563,7 +563,7 @@ bindings of each @racket[require-spec] are visible for expanding later
@racket[require-spec]s have the same identifier name but they do not refer to @racket[require-spec]s have the same identifier name but they do not refer to
the same original binding, a syntax error is reported. the same original binding, a syntax error is reported.
@defexamples[#:eval (syntax-eval) @examples[#:eval (syntax-eval) #:once
(require (combine-in (only-in racket/tcp tcp-accept) (require (combine-in (only-in racket/tcp tcp-accept)
(only-in racket/tcp tcp-listen))) (only-in racket/tcp tcp-listen)))
tcp-accept tcp-accept
@ -588,7 +588,7 @@ bindings of each @racket[require-spec] are visible for expanding later
The following example imports bindings only at @tech{phase level} 1, The following example imports bindings only at @tech{phase level} 1,
the transform phase: the transform phase:
@interaction[#:eval meta-in-eval @examples[#:label #f #:eval meta-in-eval
(module nest racket (module nest racket
(provide (for-syntax meta-eggs) (provide (for-syntax meta-eggs)
(for-meta 1 meta-chicks) (for-meta 1 meta-chicks)
@ -604,13 +604,13 @@ bindings of each @racket[require-spec] are visible for expanding later
#'(void)) #'(void))
(desc) (desc)
num-eggs (eval:error num-eggs)
] ]
The following example imports only bindings at @tech{phase level} 0, the The following example imports only bindings at @tech{phase level} 0, the
normal phase. normal phase.
@interaction[#:eval meta-in-eval @examples[#:label #f #:eval meta-in-eval
(require (only-meta-in 0 'nest)) (require (only-meta-in 0 'nest))
num-eggs num-eggs
]} ]}
@ -622,7 +622,7 @@ bindings of each @racket[require-spec] are visible for expanding later
@tech{label phase level} corresponds to @racket[#f], and a shifting @tech{label phase level} corresponds to @racket[#f], and a shifting
combination that involves @racket[#f] produces @racket[#f]. combination that involves @racket[#f] produces @racket[#f].
@defexamples[#:eval (syntax-eval) @examples[#:eval (syntax-eval) #:once
(module nest racket (module nest racket
(provide num-eggs) (provide num-eggs)
(define num-eggs 2)) (define num-eggs 2))
@ -894,7 +894,7 @@ level} 0 are imported.
(let () (let ()
(local-require racket/control) (local-require racket/control)
fcontrol) fcontrol)
fcontrol (eval:error fcontrol)
]} ]}
@ -944,7 +944,7 @@ as follows.
identifier must match (otherwise, the external name could be identifier must match (otherwise, the external name could be
ambiguous). ambiguous).
@defexamples[#:eval (syntax-eval) @examples[#:eval (syntax-eval) #:once
(module nest racket (module nest racket
(provide num-eggs) (provide num-eggs)
(define num-eggs 2)) (define num-eggs 2))
@ -968,7 +968,7 @@ as follows.
macro-introduced imports are not re-exported, unless the macro-introduced imports are not re-exported, unless the
@racket[(all-defined-out)] form was introduced at the same time. @racket[(all-defined-out)] form was introduced at the same time.
@defexamples[#:eval (syntax-eval) @examples[#:eval (syntax-eval) #:once
(module nest racket (module nest racket
(provide (all-defined-out)) (provide (all-defined-out))
(define num-eggs 2)) (define num-eggs 2))
@ -987,7 +987,7 @@ as follows.
macro-introduced imports are not re-exported, unless the macro-introduced imports are not re-exported, unless the
@racket[module-path] was introduced at the same time. @racket[module-path] was introduced at the same time.
@defexamples[#:eval (syntax-eval) @examples[#:eval (syntax-eval) #:once
(module nest racket (module nest racket
(provide num-eggs) (provide num-eggs)
(define num-eggs 2)) (define num-eggs 2))
@ -1003,13 +1003,13 @@ as follows.
the relevant @tech{phase level}. The symbolic name for each export is the relevant @tech{phase level}. The symbolic name for each export is
@racket[export-id] instead @racket[orig-d]. @racket[export-id] instead @racket[orig-d].
@defexamples[#:eval (syntax-eval) @examples[#:eval (syntax-eval) #:once
(module nest racket (module nest racket
(provide (rename-out [count num-eggs])) (provide (rename-out [count num-eggs]))
(define count 2)) (define count 2))
(require 'nest) (require 'nest)
num-eggs num-eggs
count (eval:error count)
]} ]}
@defsubform[(except-out provide-spec provide-spec ...)]{ Like the @defsubform[(except-out provide-spec provide-spec ...)]{ Like the
@ -1019,7 +1019,7 @@ as follows.
reported. The symbolic export name information in the latter reported. The symbolic export name information in the latter
@racket[provide-spec]s is ignored; only the bindings are used. @racket[provide-spec]s is ignored; only the bindings are used.
@defexamples[#:eval (syntax-eval) @examples[#:eval (syntax-eval) #:once
(module nest racket (module nest racket
(provide (except-out (all-defined-out) (provide (except-out (all-defined-out)
num-chicks)) num-chicks))
@ -1027,14 +1027,14 @@ as follows.
(define num-chicks 3)) (define num-chicks 3))
(require 'nest) (require 'nest)
num-eggs num-eggs
num-chicks (eval:error num-chicks)
]} ]}
@defsubform[(prefix-out prefix-id provide-spec)]{ @defsubform[(prefix-out prefix-id provide-spec)]{
Like @racket[provide-spec], but with each symbolic export name from Like @racket[provide-spec], but with each symbolic export name from
@racket[provide-spec] prefixed with @racket[prefix-id]. @racket[provide-spec] prefixed with @racket[prefix-id].
@defexamples[#:eval (syntax-eval) @examples[#:eval (syntax-eval) #:once
(module nest racket (module nest racket
(provide (prefix-out chicken: num-eggs)) (provide (prefix-out chicken: num-eggs))
(define num-eggs 2)) (define num-eggs 2))
@ -1055,7 +1055,7 @@ as follows.
accessor and mutator bindings of the super-type are @italic{not} accessor and mutator bindings of the super-type are @italic{not}
included by @racket[struct-out] for export. included by @racket[struct-out] for export.
@defexamples[#:eval (syntax-eval) @examples[#:eval (syntax-eval) #:once
(module nest racket (module nest racket
(provide (struct-out egg)) (provide (struct-out egg))
(struct egg (color wt))) (struct egg (color wt)))
@ -1066,7 +1066,7 @@ as follows.
@defsubform[(combine-out provide-spec ...)]{ The union of the @defsubform[(combine-out provide-spec ...)]{ The union of the
@racket[provide-spec]s. @racket[provide-spec]s.
@defexamples[#:eval (syntax-eval) @examples[#:eval (syntax-eval) #:once
(module nest racket (module nest racket
(provide (combine-out num-eggs num-chicks)) (provide (combine-out num-eggs num-chicks))
(define num-eggs 2) (define num-eggs 2)
@ -1084,7 +1084,7 @@ as follows.
For more details, see @secref["modprotect"]. The @racket[provide-spec] must specify only For more details, see @secref["modprotect"]. The @racket[provide-spec] must specify only
bindings that are defined within the exporting module. bindings that are defined within the exporting module.
@examples[#:eval (syntax-eval) @examples[#:eval (syntax-eval) #:once
(module nest racket (module nest racket
(provide num-eggs (protect-out num-chicks)) (provide num-eggs (protect-out num-chicks))
(define num-eggs 2) (define num-eggs 2)
@ -1102,7 +1102,7 @@ as follows.
(require 'nest) (require 'nest)
(list num-eggs num-chicks) (list num-eggs num-chicks)
(weak-eval 'num-eggs) (weak-eval 'num-eggs)
(weak-eval 'num-chicks) (eval:error (weak-eval 'num-chicks))
]} ]}
@specsubform[#:literals (for-meta) @specsubform[#:literals (for-meta)
@ -1118,7 +1118,7 @@ as follows.
@racket[all-from-out] exports bindings imported with a shift by @racket[all-from-out] exports bindings imported with a shift by
@racket[phase-level]. @racket[phase-level].
@examples[#:eval (syntax-eval) @examples[#:eval (syntax-eval) #:once
(module nest racket (module nest racket
(begin-for-syntax (begin-for-syntax
(define eggs 2)) (define eggs 2))
@ -1132,11 +1132,12 @@ as follows.
(test-eggs) (test-eggs)
chickens chickens
(module broken-nest racket (eval:error
(define eggs 2) (module broken-nest racket
(define chickens 3) (define eggs 2)
(provide (for-syntax eggs) (define chickens 3)
chickens)) (provide (for-syntax eggs)
chickens)))
(module nest2 racket (module nest2 racket
(begin-for-syntax (begin-for-syntax
@ -1309,7 +1310,7 @@ Like @racket[require-spec], but including only imports whose names
match @racket[regexp]. The @racket[regexp] must be a literal regular match @racket[regexp]. The @racket[regexp] must be a literal regular
expression (see @secref["regexp"]). expression (see @secref["regexp"]).
@defexamples[#:eval (syntax-eval) @examples[#:eval (syntax-eval) #:once
(module zoo racket/base (module zoo racket/base
(provide tunafish swordfish blowfish (provide tunafish swordfish blowfish
monkey lizard ant) monkey lizard ant)
@ -1324,7 +1325,7 @@ Like @racket[require-spec], but including only imports whose names
tunafish tunafish
swordfish swordfish
blowfish blowfish
monkey (eval:error monkey)
]} ]}
@defform[(subtract-in require-spec subtracted-spec ...)]{ @defform[(subtract-in require-spec subtracted-spec ...)]{
@ -1332,7 +1333,7 @@ monkey
Like @racket[require-spec], but omitting those imports that would be Like @racket[require-spec], but omitting those imports that would be
imported by one of the @racket[subtracted-spec]s. imported by one of the @racket[subtracted-spec]s.
@defexamples[#:eval (syntax-eval) @examples[#:eval (syntax-eval) #:once
(module earth racket (module earth racket
(provide land sea air) (provide land sea air)
(define land 1) (define land 1)
@ -1350,7 +1351,7 @@ Like @racket[require-spec], but omitting those imports that would be
(require racket/require) (require racket/require)
(require (subtract-in 'solar-system 'earth)) (require (subtract-in 'solar-system 'earth))
land (eval:error land)
aliens aliens
]} ]}
@ -1517,7 +1518,7 @@ introduces @racketidfont{#%datum} identifiers.
@mz-examples[ @mz-examples[
(#%datum . 10) (#%datum . 10)
(#%datum . x) (#%datum . x)
(#%datum . #:x) (eval:error (#%datum . #:x))
] ]
} }
@ -1532,14 +1533,14 @@ expression.
@mz-examples[ @mz-examples[
(#%expression (+ 1 2)) (#%expression (+ 1 2))
(#%expression (define x 10)) (eval:error (#%expression (define x 10)))
] ]
The @racket[#%expression] form is helpful in recursive definition contexts The @racket[#%expression] form is helpful in recursive definition contexts
where expanding a subsequent definition can provide compile-time information where expanding a subsequent definition can provide compile-time information
for the current expression. For example, consider a @racket[define-sym-case] for the current expression. For example, consider a @racket[define-sym-case]
macro that simply records some symbols at compile-time in a given identifier. macro that simply records some symbols at compile-time in a given identifier.
@interaction/no-prompt[#:eval meta-in-eval @examples[#:label #f #:no-prompt #:eval meta-in-eval
(define-syntax (define-sym-case stx) (define-syntax (define-sym-case stx)
(syntax-case stx () (syntax-case stx ()
[(_ id sym ...) [(_ id sym ...)
@ -1548,7 +1549,7 @@ macro that simply records some symbols at compile-time in a given identifier.
'(sym ...))]))] '(sym ...))]))]
and then a variant of @racket[case] that checks to make sure the symbols and then a variant of @racket[case] that checks to make sure the symbols
used in the expression match those given in the earlier definition: used in the expression match those given in the earlier definition:
@interaction/no-prompt[#:eval meta-in-eval @examples[#:label #f #:no-prompt #:eval meta-in-eval
(define-syntax (sym-case stx) (define-syntax (sym-case stx)
(syntax-case stx () (syntax-case stx ()
[(_ id val-expr [(sym) expr] ...) [(_ id val-expr [(sym) expr] ...)
@ -1575,18 +1576,19 @@ If the definition follows the use like this, then
the @racket[define-sym-case] macro does not have the @racket[define-sym-case] macro does not have
a chance to bind @racket[id] and the @racket[sym-case] a chance to bind @racket[id] and the @racket[sym-case]
macro signals an error: macro signals an error:
@interaction[#:eval meta-in-eval @examples[#:label #f #:eval meta-in-eval
(let () (eval:error
(sym-case land-creatures 'bear (let ()
[(bear) 1] (sym-case land-creatures 'bear
[(fox) 2]) [(bear) 1]
(define-sym-case land-creatures bear fox)) [(fox) 2])
(define-sym-case land-creatures bear fox)))
] ]
But if the @racket[sym-case] is wrapped in an @racket[#%expression], But if the @racket[sym-case] is wrapped in an @racket[#%expression],
then the expander does not need to expand it to know it is then the expander does not need to expand it to know it is
an expression and it moves on to the @racket[define-sym-case] an expression and it moves on to the @racket[define-sym-case]
expression. expression.
@interaction[#:eval meta-in-eval @examples[#:label #f #:eval meta-in-eval
(let () (let ()
(#%expression (sym-case sea-creatures 'whale (#%expression (sym-case sea-creatures 'whale
[(whale) 1] [(whale) 1]
@ -1740,7 +1742,7 @@ expander introduces @racketidfont{#%app} identifiers.
@mz-examples[ @mz-examples[
(#%app + 1 2) (#%app + 1 2)
(#%app (lambda (x #:arg y) (list y x)) #:arg 2 1) (#%app (lambda (x #:arg y) (list y x)) #:arg 2 1)
(#%app cons) (eval:error (#%app cons))
]} ]}
@defform*[[(#%plain-app proc-expr arg-expr ...) @defform*[[(#%plain-app proc-expr arg-expr ...)
@ -2342,13 +2344,14 @@ in @math{O(log N)} time for @math{N} @racket[datum]s.
(case (list 'quote 'x) (case (list 'quote 'x)
[(x) "ex"] [(x) "ex"]
[('x) "quoted ex"]) [('x) "quoted ex"])
]
@def+int[ (eval:no-prompt
(define (classify c) (define (classify c)
(case (char-general-category c) (case (char-general-category c)
[(ll lu lt ln lo) "letter"] [(ll lu lt ln lo) "letter"]
[(nd nl no) "number"] [(nd nl no) "number"]
[else "other"])) [else "other"])))
(classify #\A) (classify #\A)
(classify #\1) (classify #\1)
(classify #\!) (classify #\!)
@ -2394,19 +2397,20 @@ In a context that allows @tech{liberal expansion} of @racket[define],
@racket[lambda] form with keyword arguments or @racket[args] include @racket[lambda] form with keyword arguments or @racket[args] include
keyword arguments. keyword arguments.
@defexamples[ @examples[
(define x 10) (eval:no-prompt (define x 10))
x x
]
@def+int[
(define (f x)
(+ x 1))
(f 10)
]
@def+int[ (eval:no-prompt
(define ((f x) [y 20]) (define (f x)
(+ x y)) (+ x 1)))
(f 10)
(eval:no-prompt
(define ((f x) [y 20])
(+ x y)))
((f 10) 30) ((f 10) 30)
((f 10)) ((f 10))
] ]
@ -2427,7 +2431,7 @@ and the top-level mapping of each @racket[id] (in the
@techlink{namespace} linked with the compiled definition) is set to @techlink{namespace} linked with the compiled definition) is set to
the binding at the same time. the binding at the same time.
@defexamples[ @examples[
(define-values () (values)) (define-values () (values))
(define-values (x y z) (values 1 2 3)) (define-values (x y z) (values 1 2 3))
z z
@ -2459,7 +2463,7 @@ expands to a definition of the first form where the @racket[expr] is a
In an @tech{internal-definition context} (see @secref["intdef-body"]), In an @tech{internal-definition context} (see @secref["intdef-body"]),
a @racket[define-syntax] form introduces a local binding. a @racket[define-syntax] form introduces a local binding.
@defexamples[#:eval (syntax-eval) @examples[#:eval (syntax-eval) #:once
(define-syntax foo (define-syntax foo
(syntax-rules () (syntax-rules ()
((_ a ...) ((_ a ...)
@ -2490,7 +2494,7 @@ binding; see @secref["macro-introduced-bindings"].
In an @tech{internal-definition context} (see @secref["intdef-body"]), In an @tech{internal-definition context} (see @secref["intdef-body"]),
a @racket[define-syntaxes] form introduces local bindings. a @racket[define-syntaxes] form introduces local bindings.
@defexamples[#:eval (syntax-eval) @examples[#:eval (syntax-eval) #:once
(define-syntaxes (foo1 foo2 foo3) (define-syntaxes (foo1 foo2 foo3)
(let ([transformer1 (lambda (syntax-object) (let ([transformer1 (lambda (syntax-object)
(syntax-case syntax-object () (syntax-case syntax-object ()
@ -2526,14 +2530,14 @@ form must be expanded before the use is expanded). In particular,
mutually recursive functions bound by @racket[define-for-syntax] must mutually recursive functions bound by @racket[define-for-syntax] must
be defined by the same @racket[define-for-syntax] form. be defined by the same @racket[define-for-syntax] form.
@defexamples[#:eval (syntax-eval) @examples[#:eval (syntax-eval) #:once
(define-for-syntax helper 2) (define-for-syntax helper 2)
(define-syntax (make-two syntax-object) (define-syntax (make-two syntax-object)
(printf "helper is ~a\n" helper) (printf "helper is ~a\n" helper)
#'2) #'2)
(make-two) (make-two)
(code:comment @#,t{`helper' is not bound in the runtime phase}) (code:comment @#,t{`helper' is not bound in the runtime phase})
helper (eval:error helper)
(define-for-syntax (filter-ids ids) (define-for-syntax (filter-ids ids)
(filter identifier? ids)) (filter identifier? ids))
@ -2552,7 +2556,7 @@ Like @racket[define-for-syntax], but @racket[expr] must produce as
many values as supplied @racket[id]s, and all of the @racket[id]s are many values as supplied @racket[id]s, and all of the @racket[id]s are
bound (at @tech{phase level} 1).} bound (at @tech{phase level} 1).}
@defexamples[#:eval (syntax-eval) @examples[#:eval (syntax-eval) #:once
(define-values-for-syntax (foo1 foo2) (values 1 2)) (define-values-for-syntax (foo1 foo2) (values 1 2))
(define-syntax (bar syntax-object) (define-syntax (bar syntax-object)
(printf "foo1 is ~a foo2 is ~a\n" foo1 foo2) (printf "foo1 is ~a foo2 is ~a\n" foo1 foo2)
@ -2768,14 +2772,14 @@ variable} that has not been defined, the @exnraise[exn:fail:contract].
See also @racket[compile-allow-set!-undefined]. See also @racket[compile-allow-set!-undefined].
@defexamples[ @examples[
(define x 12) (define x 12)
(set! x (add1 x)) (set! x (add1 x))
x x
(let ([x 5]) (let ([x 5])
(set! x (add1 x)) (set! x (add1 x))
x) x)
(set! i-am-not-defined 10) (eval:error (set! i-am-not-defined 10))
]} ]}
@defform[(set!-values (id ...) expr)]{ @defform[(set!-values (id ...) expr)]{
@ -2859,7 +2863,7 @@ other way than as @racket[(#,unquote-id _expr)] or
(eval:alts (#,(racket quasiquote) (0 1 2)) `(0 1 2)) (eval:alts (#,(racket quasiquote) (0 1 2)) `(0 1 2))
(eval:alts (#,(racket quasiquote) (0 (#,unquote-id (+ 1 2)) 4)) `(0 ,(+ 1 2) 4)) (eval:alts (#,(racket quasiquote) (0 (#,unquote-id (+ 1 2)) 4)) `(0 ,(+ 1 2) 4))
(eval:alts (#,(racket quasiquote) (0 (#,unquote-splicing-id (list 1 2)) 4)) `(0 ,@(list 1 2) 4)) (eval:alts (#,(racket quasiquote) (0 (#,unquote-splicing-id (list 1 2)) 4)) `(0 ,@(list 1 2) 4))
(eval:alts (#,(racket quasiquote) (0 (#,unquote-splicing-id 1) 4)) `(0 ,@1 4)) (eval:error (eval:alts (#,(racket quasiquote) (0 (#,unquote-splicing-id 1) 4)) `(0 ,@1 4)))
(eval:alts (#,(racket quasiquote) (0 (#,unquote-splicing-id 1))) `(0 ,@1)) (eval:alts (#,(racket quasiquote) (0 (#,unquote-splicing-id 1))) `(0 ,@1))
] ]

View File

@ -1,6 +1,5 @@
#lang scribble/doc #lang scribble/doc
@(require "mz.rkt" (for-label racket/trace) @(require "mz.rkt" (for-label racket/trace))
scribble/eval)
@(begin (define ev (make-base-eval)) @(begin (define ev (make-base-eval))
(ev '(require racket/trace)) (ev '(require racket/trace))

View File

@ -31,5 +31,5 @@ the @racket[call-with-values] call.
@examples[ @examples[
(call-with-values (lambda () (values 1 2)) +) (call-with-values (lambda () (values 1 2)) +)
(call-with-values (lambda () 1) (lambda (x y) (+ x y))) (eval:error (call-with-values (lambda () 1) (lambda (x y) (+ x y))))
]} ]}

View File

@ -151,8 +151,8 @@ _i)] is the value produced by @racket[(proc _i)].
@note-lib[racket/vector] @note-lib[racket/vector]
@(define vec-eval (make-base-eval)) @(define vec-eval (make-base-eval))
@(interaction-eval #:eval vec-eval @examples[#:hidden #:eval vec-eval
(require racket/vector)) (require racket/vector)]
@defproc[(vector-set*! [vec (and/c vector? (not/c immutable?))] @defproc[(vector-set*! [vec (and/c vector? (not/c immutable?))]
[pos exact-nonnegative-integer?] [pos exact-nonnegative-integer?]