From 4354ce45d8658cbad5005f56e02b48b1e6a5ccd0 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Fri, 11 Dec 2015 10:06:13 -0700 Subject: [PATCH] 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. --- .../compatibility/scribblings/package.scrbl | 10 +- pkgs/racket-doc/info.rkt | 2 +- .../reference/async-channels.scrbl | 42 +- .../scribblings/reference/block.scrbl | 2 +- .../scribblings/reference/bytes.scrbl | 2 +- .../scribblings/reference/chaperones.scrbl | 20 +- .../scribblings/reference/class.scrbl | 642 +++++++++--------- .../scribblings/reference/contracts.scrbl | 229 ++++--- .../scribblings/reference/custom-ports.scrbl | 4 +- .../scribblings/reference/custom-write.scrbl | 38 +- .../scribblings/reference/define-struct.scrbl | 68 +- .../scribblings/reference/dicts.scrbl | 16 +- .../scribblings/reference/evts.scrbl | 1 - .../scribblings/reference/exns.scrbl | 25 +- .../scribblings/reference/fasl.scrbl | 2 +- .../scribblings/reference/file-ports.scrbl | 4 +- .../scribblings/reference/filesystem.scrbl | 10 +- .../scribblings/reference/fixnums.scrbl | 2 +- .../scribblings/reference/flonums.scrbl | 2 +- .../scribblings/reference/for.scrbl | 18 +- .../scribblings/reference/format.scrbl | 43 +- .../scribblings/reference/futures.scrbl | 4 +- .../scribblings/reference/generic.scrbl | 4 +- .../scribblings/reference/hashes.scrbl | 4 +- .../scribblings/reference/logging.scrbl | 8 +- .../scribblings/reference/match.scrbl | 53 +- pkgs/racket-doc/scribblings/reference/mz.rkt | 4 +- .../scribblings/reference/numbers.scrbl | 12 +- .../scribblings/reference/pairs.scrbl | 18 +- .../scribblings/reference/port-lib.scrbl | 2 +- .../scribblings/reference/procedures.scrbl | 72 +- .../scribblings/reference/regexps.scrbl | 2 +- .../scribblings/reference/sandbox.scrbl | 18 +- .../scribblings/reference/sequences.scrbl | 56 +- .../scribblings/reference/serialization.scrbl | 2 +- .../scribblings/reference/sets.scrbl | 7 +- .../scribblings/reference/shared.scrbl | 12 +- .../scribblings/reference/splicing.scrbl | 15 +- .../scribblings/reference/string-ports.scrbl | 2 +- .../scribblings/reference/strings.scrbl | 2 +- .../scribblings/reference/struct.scrbl | 60 +- .../scribblings/reference/stx-comp.scrbl | 2 +- .../scribblings/reference/stx-ops.scrbl | 2 +- .../scribblings/reference/stx-param.scrbl | 5 +- .../scribblings/reference/stx-trans.scrbl | 4 +- .../scribblings/reference/syntax-model.scrbl | 4 +- .../scribblings/reference/syntax-util.scrbl | 11 +- .../scribblings/reference/syntax.scrbl | 152 +++-- .../scribblings/reference/trace.scrbl | 3 +- .../scribblings/reference/values.scrbl | 2 +- .../scribblings/reference/vectors.scrbl | 4 +- 51 files changed, 898 insertions(+), 830 deletions(-) diff --git a/pkgs/racket-doc/compatibility/scribblings/package.scrbl b/pkgs/racket-doc/compatibility/scribblings/package.scrbl index 16f5939195..278b64082d 100644 --- a/pkgs/racket-doc/compatibility/scribblings/package.scrbl +++ b/pkgs/racket-doc/compatibility/scribblings/package.scrbl @@ -2,7 +2,7 @@ @(require scribblings/reference/mz (for-label compatibility/package)) @(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], ...} @@ -61,11 +61,11 @@ is the exported one. (define-package presents (doll) (define doll "Molly Coddle") (define robot "Destructo")) -doll -robot +(eval:error doll) +(eval:error robot) (open-package presents) doll -robot +(eval:error robot) (define-package big-russian-doll (middle-russian-doll) (define-package middle-russian-doll (little-russian-doll) (define little-russian-doll "Anastasia"))) @@ -95,7 +95,7 @@ the defined bindings remain hidden outside the (package-begin (define secret "mimi") (list secret)) -secret +(eval:error secret) ]} @deftogether[( diff --git a/pkgs/racket-doc/info.rkt b/pkgs/racket-doc/info.rkt index 48eca51fa1..e80f691186 100644 --- a/pkgs/racket-doc/info.rkt +++ b/pkgs/racket-doc/info.rkt @@ -6,7 +6,7 @@ "base" "net-lib" "sandbox-lib" - "scribble-lib" + ["scribble-lib" #:version "1.14"] "racket-index")) (define build-deps '("rackunit-doc" "compatibility" diff --git a/pkgs/racket-doc/scribblings/reference/async-channels.scrbl b/pkgs/racket-doc/scribblings/reference/async-channels.scrbl index 9da432a95e..9c4d6bcc85 100644 --- a/pkgs/racket-doc/scribblings/reference/async-channels.scrbl +++ b/pkgs/racket-doc/scribblings/reference/async-channels.scrbl @@ -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 limit); @resultItself{asychronous channel-put event}.} -@defexamples[#:eval (async-eval) -(define (server input-channel output-channel) - (thread (lambda () - (define (get) - (async-channel-get input-channel)) - (define (put x) - (async-channel-put output-channel x)) - (define (do-large-computation) - (sqrt 9)) - (let loop ([data (get)]) - (case data - [(quit) (void)] - [(add) (begin - (put (+ 1 (get))) - (loop (get)))] - [(long) (begin - (put (do-large-computation)) - (loop (get)))]))))) - -(define to-server (make-async-channel)) -(define from-server (make-async-channel)) +@examples[#:eval (async-eval) #:once +(eval:no-prompt + (define (server input-channel output-channel) + (thread (lambda () + (define (get) + (async-channel-get input-channel)) + (define (put x) + (async-channel-put output-channel x)) + (define (do-large-computation) + (sqrt 9)) + (let loop ([data (get)]) + (case data + [(quit) (void)] + [(add) (begin + (put (+ 1 (get))) + (loop (get)))] + [(long) (begin + (put (do-large-computation)) + (loop (get)))]))))) + (define to-server (make-async-channel)) + (define from-server (make-async-channel))) (server to-server from-server) diff --git a/pkgs/racket-doc/scribblings/reference/block.scrbl b/pkgs/racket-doc/scribblings/reference/block.scrbl index 61a3aad2ad..2d757c3c92 100644 --- a/pkgs/racket-doc/scribblings/reference/block.scrbl +++ b/pkgs/racket-doc/scribblings/reference/block.scrbl @@ -1,5 +1,5 @@ #lang scribble/doc -@(require "mz.rkt" scribble/eval (for-label racket/block)) +@(require "mz.rkt" (for-label racket/block)) @(define ev (make-base-eval)) @(ev '(require racket/block)) diff --git a/pkgs/racket-doc/scribblings/reference/bytes.scrbl b/pkgs/racket-doc/scribblings/reference/bytes.scrbl index 4b2f62222f..97de7fdd4b 100644 --- a/pkgs/racket-doc/scribblings/reference/bytes.scrbl +++ b/pkgs/racket-doc/scribblings/reference/bytes.scrbl @@ -643,7 +643,7 @@ normally identified by @racket[""]). See also @section{Additional Byte String Functions} @note-lib[racket/bytes] @(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?]{ @; Note: this is exactly the same description as the one for append* diff --git a/pkgs/racket-doc/scribblings/reference/chaperones.scrbl b/pkgs/racket-doc/scribblings/reference/chaperones.scrbl index 646be4c8ec..ec16c2cbbf 100644 --- a/pkgs/racket-doc/scribblings/reference/chaperones.scrbl +++ b/pkgs/racket-doc/scribblings/reference/chaperones.scrbl @@ -924,11 +924,12 @@ procedure. (lambda (n) (* n 2)) (lambda (n) (+ n 1)))) - (call-with-continuation-prompt - (lambda () - (abort-current-continuation bad-chaperone 5)) - bad-chaperone - (lambda (n) n)) + (eval:error + (call-with-continuation-prompt + (lambda () + (abort-current-continuation bad-chaperone 5)) + bad-chaperone + (lambda (n) n))) (define good-chaperone (chaperone-prompt-tag @@ -966,10 +967,11 @@ given. (lambda (l) (map char-upcase l)) string->list)) - (with-continuation-mark bad-chaperone "timballo" - (continuation-mark-set-first - (current-continuation-marks) - bad-chaperone)) + (eval:error + (with-continuation-mark bad-chaperone "timballo" + (continuation-mark-set-first + (current-continuation-marks) + bad-chaperone))) (define (checker s) (if (> (string-length s) 5) diff --git a/pkgs/racket-doc/scribblings/reference/class.scrbl b/pkgs/racket-doc/scribblings/reference/class.scrbl index 9eb15c1fb7..e95455db04 100644 --- a/pkgs/racket-doc/scribblings/reference/class.scrbl +++ b/pkgs/racket-doc/scribblings/reference/class.scrbl @@ -71,11 +71,10 @@ ) -@(interaction-eval #:eval class-eval (require racket/class racket/contract)) -@(interaction-eval - #:eval class-ctc-eval - (require racket/class racket/contract)) - +@examples[#:hidden #:eval class-eval + (require racket/class racket/contract)] +@examples[#:hidden #:eval class-ctc-eval + (require racket/class racket/contract)] @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 @exnraise[exn:fail:object]. -@defexamples[ +@examples[ #:eval class-ctc-eval +#:no-prompt (define file-interface<%> (interface () open close read-byte write-byte)) (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 structure type property's guard, if any). -@defexamples[ +@examples[ #:eval class-eval +#:no-prompt (define i<%> (interface* () ([prop:custom-write (lambda (obj port mode) (void))]) 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. -@defexamples[ +@examples[ #:eval class-eval +#:no-prompt (define book-class% (class object% (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 a syntax error. -@defexamples[ +@examples[ #:eval class-eval -(define (describe obj) - (printf "Hello ~a\n" obj)) -(define table% - (class object% - (define/public (describe-self) - (describe this)) - (super-new))) +(eval:no-prompt + (define (describe obj) + (printf "Hello ~a\n" obj)) + (define table% + (class object% + (define/public (describe-self) + (describe this)) + (super-new)))) (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 a syntax error. -@defexamples[ +@examples[ #:eval class-eval -(define account% - (class object% - (super-new) - (init-field balance) - (define/public (add n) - (new this% [balance (+ n balance)])))) -(define savings% - (class account% - (super-new) - (inherit-field balance) - (define interest 0.04) - (define/public (add-interest) - (send this add (* interest balance))))) +(eval:no-prompt + (define account% + (class object% + (super-new) + (init-field balance) + (define/public (add n) + (new this% [balance (+ n balance)])))) + (define savings% + (class account% + (super-new) + (inherit-field balance) + (define interest 0.04) + (define/public (add-interest) + (send this add (* interest balance)))))) (let* ([acct (new savings% [balance 500])] [acct (send acct add 500)] [acct (send acct add-interest)]) @@ -447,7 +451,7 @@ a syntax error. @defclassforms[ [(inspect inspector-expr) ()] [(init init-decl ...) ("clinitvars") - @defexamples[#:eval class-eval + @examples[#:eval class-eval (class object% (super-new) (init turnip @@ -455,7 +459,7 @@ a syntax error. [carrot 'good] [(internal-rutabaga rutabaga) 'okay]))]] [(init-field init-decl ...) ("clinitvars" "clfields") - @defexamples[#:eval class-eval + @examples[#:eval class-eval (class object% (super-new) (init-field turkey @@ -463,181 +467,202 @@ a syntax error. [chicken 7] [(internal-emu emu) 13]))]] [(field field-decl ...) ("clfields") - @defexamples[#:eval class-eval + @examples[#:eval class-eval (class object% (super-new) (field [minestrone 'ready] [(internal-coq-au-vin coq-au-vin) 'stewing]))]] [(inherit-field maybe-renamed ...) ("clfields") - @defexamples[#:eval class-eval - (define cookbook% - (class object% - (super-new) - (field [recipes '(caldo-verde oyakodon eggs-benedict)] - [pages 389]))) + @examples[#:eval class-eval + (eval:no-prompt + (define cookbook% + (class object% + (super-new) + (field [recipes '(caldo-verde oyakodon eggs-benedict)] + [pages 389])))) (class cookbook% (super-new) (inherit-field recipes [internal-pages pages]))]] [* ((init-rest id) (init-rest)) ("clinitvars") - @defexamples[#:eval class-eval - (define fruit-basket% - (class object% - (super-new) - (init-rest fruits) - (displayln fruits))) - (make-object fruit-basket% 'kiwi 'lychee 'melon)]] - [(public maybe-renamed ...) ("clmethoddefs") - @defexamples[#:eval class-eval - (define jumper% + @examples[#:eval class-eval + (eval:no-prompt + (define fruit-basket% (class object% (super-new) - (define (skip) 'skip) - (define (hop) 'hop) - (public skip [hop jump]))) + (init-rest fruits) + (displayln fruits)))) + (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%) jump)]] [(pubment maybe-renamed ...) ("clmethoddefs") - @defexamples[#:eval class-eval - (define runner% - (class object% - (super-new) - (define (run) 'run) - (define (trot) 'trot) - (pubment run [trot jog]))) + @examples[#:eval class-eval + (eval:no-prompt + (define runner% + (class object% + (super-new) + (define (run) 'run) + (define (trot) 'trot) + (pubment run [trot jog])))) (send (new runner%) run) (send (new runner%) jog)]] [(public-final maybe-renamed ...) ("clmethoddefs") - @defexamples[#:eval class-eval - (define point% - (class object% - (super-new) - (init-field [x 0] [y 0]) - (define (get-x) x) - (define (do-get-y) y) - (public-final get-x [do-get-y get-y]))) + @examples[#:eval class-eval + (eval:no-prompt + (define point% + (class object% + (super-new) + (init-field [x 0] [y 0]) + (define (get-x) x) + (define (do-get-y) y) + (public-final get-x [do-get-y get-y])))) (send (new point% [x 1] [y 3]) get-y) - (class point% - (super-new) - (define (get-x) 3.14) - (override get-x))]] + (eval:error + (class point% + (super-new) + (define (get-x) 3.14) + (override get-x)))]] [(override maybe-renamed ...) ("clmethoddefs") - @defexamples[#:eval class-eval - (define sheep% - (class object% - (super-new) - (define/public (bleat) - (displayln "baaaaaaaaah")))) - (define confused-sheep% - (class sheep% - (super-new) - (define (bleat) - (super bleat) - (displayln "???")) - (override bleat))) + @examples[#:eval class-eval + (eval:no-prompt + (define sheep% + (class object% + (super-new) + (define/public (bleat) + (displayln "baaaaaaaaah"))))) + (eval:no-prompt + (define confused-sheep% + (class sheep% + (super-new) + (define (bleat) + (super bleat) + (displayln "???")) + (override bleat)))) (send (new sheep%) bleat) (send (new confused-sheep%) bleat)]] [(overment maybe-renamed ...) ("clmethoddefs") - @defexamples[#:eval class-eval - (define turkey% - (class object% - (super-new) - (define/public (gobble) - (displayln "gobble gobble")))) - (define extra-turkey% - (class turkey% - (super-new) - (define (gobble) - (super gobble) - (displayln "gobble gobble gobble") - (inner (void) gobble)) - (overment gobble))) - (define cyborg-turkey% - (class extra-turkey% - (super-new) - (define/augment (gobble) - (displayln "110011111011111100010110001011011001100101")))) + @examples[#:eval class-eval + (eval:no-prompt + (define turkey% + (class object% + (super-new) + (define/public (gobble) + (displayln "gobble gobble"))))) + (eval:no-prompt + (define extra-turkey% + (class turkey% + (super-new) + (define (gobble) + (super gobble) + (displayln "gobble gobble gobble") + (inner (void) gobble)) + (overment gobble)))) + (eval:no-prompt + (define cyborg-turkey% + (class extra-turkey% + (super-new) + (define/augment (gobble) + (displayln "110011111011111100010110001011011001100101"))))) (send (new extra-turkey%) gobble) (send (new cyborg-turkey%) gobble)]] [(override-final maybe-renamed ...) ("clmethoddefs") - @defexamples[#:eval class-eval - (define meeper% - (class object% - (super-new) - (define/public (meep) - (displayln "meep")))) - (define final-meeper% - (class meeper% - (super-new) - (define (meep) - (super meep) - (displayln "This meeping ends with me")) - (override-final meep))) + @examples[#:eval class-eval + (eval:no-prompt + (define meeper% + (class object% + (super-new) + (define/public (meep) + (displayln "meep"))))) + (eval:no-prompt + (define final-meeper% + (class meeper% + (super-new) + (define (meep) + (super meep) + (displayln "This meeping ends with me")) + (override-final meep)))) (send (new meeper%) meep) (send (new final-meeper%) meep)]] [(augment maybe-renamed ...) ("clmethoddefs") - @defexamples[#:eval class-eval - (define buzzer% - (class object% - (super-new) - (define/pubment (buzz) - (displayln "bzzzt") - (inner (void) buzz)))) - (define loud-buzzer% - (class buzzer% - (super-new) - (define (buzz) - (displayln "BZZZZZZZZZT")) - (augment buzz))) + @examples[#:eval class-eval + (eval:no-prompt + (define buzzer% + (class object% + (super-new) + (define/pubment (buzz) + (displayln "bzzzt") + (inner (void) buzz))))) + (eval:no-prompt + (define loud-buzzer% + (class buzzer% + (super-new) + (define (buzz) + (displayln "BZZZZZZZZZT")) + (augment buzz)))) (send (new buzzer%) buzz) (send (new loud-buzzer%) buzz)]] [(augride maybe-renamed ...) ("clmethoddefs")] [(augment-final maybe-renamed ...) ("clmethoddefs")] [(private id ...) ("clmethoddefs") - @defexamples[#:eval class-eval - (define light% - (class object% - (super-new) - (define on? #t) - (define (toggle) (set! on? (not on?))) - (private toggle) - (define (flick) (toggle)) - (public flick))) - (send (new light%) toggle) + @examples[#:eval class-eval + (eval:no-prompt + (define light% + (class object% + (super-new) + (define on? #t) + (define (toggle) (set! on? (not on?))) + (private toggle) + (define (flick) (toggle)) + (public flick)))) + (eval:error (send (new light%) toggle)) (send (new light%) flick)]] [(abstract id ...) ("clmethoddefs") - @defexamples[#:eval class-eval - (define train% - (class object% - (super-new) - (abstract get-speed) - (init-field [position 0]) - (define/public (move) - (new this% [position (+ position (get-speed))])))) - (define acela% - (class train% - (super-new) - (define/override (get-speed) 241))) - (define talgo-350% - (class train% - (super-new) - (define/override (get-speed) 330))) - (new train%) + @examples[#:eval class-eval + (eval:no-prompt + (define train% + (class object% + (super-new) + (abstract get-speed) + (init-field [position 0]) + (define/public (move) + (new this% [position (+ position (get-speed))]))))) + (eval:no-prompt + (define acela% + (class train% + (super-new) + (define/override (get-speed) 241)))) + (eval:no-prompt + (define talgo-350% + (class train% + (super-new) + (define/override (get-speed) 330)))) + (eval:error (new train%)) (send (new acela%) move)]] [(inherit maybe-renamed ...) ("classinherit") - @defexamples[#:eval class-eval - (define alarm% - (class object% - (super-new) - (define/public (alarm) - (displayln "beeeeeeeep")))) - (define car-alarm% - (class alarm% - (super-new) - (init-field proximity) - (inherit alarm) - (when (< proximity 10) - (alarm)))) + @examples[#:eval class-eval + (eval:no-prompt + (define alarm% + (class object% + (super-new) + (define/public (alarm) + (displayln "beeeeeeeep"))))) + (eval:no-prompt + (define car-alarm% + (class alarm% + (super-new) + (init-field proximity) + (inherit alarm) + (when (< proximity 10) + (alarm))))) (new car-alarm% [proximity 5])]] [(inherit/super 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 names. -@defexamples[ +@examples[ #:eval class-eval -(define-values (r o) - (let () - (define-local-member-name m) - (define c% (class object% - (define/public (m) 10) - (super-new))) - (define o (new c%)) +(eval:no-prompt + (define-values (r o) + (let () + (define-local-member-name m) + (define c% (class object% + (define/public (m) 10) + (super-new))) + (define o (new c%)) - (values (send o m) - o))) + (values (send o m) + o)))) 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[equal-hash-code].} -@defexamples[ +@examples[ #:eval class-eval -(define (make-c% key) - (define-member-name m key) - (class object% - (define/public (m) 10) - (super-new))) +(eval:no-prompt + (define (make-c% key) + (define-member-name m key) + (class object% + (define/public (m) 10) + (super-new)))) (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) -] -@defs+int[ -#:eval class-eval -[(define (fresh-c%) +(eval:no-prompt + (define (fresh-c%) (let ([key (generate-member-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 () (define-member-name p key) (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*]. -@defexamples[#:eval class-eval -(define point% - (class object% - (super-new) - (init-field [x 0] [y 0]) - (define/public (move-x dx) - (new this% [x (+ x dx)])) - (define/public (move-y dy) - (new this% [y (+ y dy)])))) +@examples[#:eval class-eval +(eval:no-prompt + (define point% + (class object% + (super-new) + (init-field [x 0] [y 0]) + (define/public (move-x dx) + (new this% [x (+ x dx)])) + (define/public (move-y dy) + (new this% [y (+ y dy)]))))) (send+ (new point%) (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 that the method is present in the class. - @defexamples[#:eval - class-eval - (define woody% - (class object% - (define/public (draw who) - (format "reach for the sky, ~a" who)) - (super-new))) + @examples[#:eval class-eval + (eval:no-prompt + (define woody% + (class object% + (define/public (draw who) + (format "reach for the sky, ~a" who)) + (super-new))) - (define/contract woody+c% - (class/c [draw (->m symbol? string?)]) - woody%) + (define/contract woody+c% + (class/c [draw (->m symbol? string?)]) + woody%)) (send (new woody%) draw #f) (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 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 contract @racket[any/c] (but it is checked more efficiently). - @defexamples[#:eval - class-eval - (define woody/hat% - (class woody% - (field [hat-location 'uninitialized]) - (define/public (lose-hat) (set! hat-location 'lost)) - (define/public (find-hat) (set! hat-location 'on-head)) - (super-new))) - (define/contract woody/hat+c% - (class/c [draw (->m symbol? string?)] - [lose-hat (->m void?)] - [find-hat (->m void?)] - (field [hat-location (or/c 'on-head 'lost)])) - woody/hat%) + @examples[#:eval class-eval + (eval:no-prompt + (define woody/hat% + (class woody% + (field [hat-location 'uninitialized]) + (define/public (lose-hat) (set! hat-location 'lost)) + (define/public (find-hat) (set! hat-location 'on-head)) + (super-new))) + (define/contract woody/hat+c% + (class/c [draw (->m symbol? string?)] + [lose-hat (->m void?)] + [find-hat (->m void?)] + (field [hat-location (or/c 'on-head 'lost)])) + woody/hat%)) (get-field hat-location (new woody/hat%)) (let ([woody (new woody/hat+c%)]) (send woody lose-hat) (get-field hat-location woody)) - (get-field hat-location (new woody/hat+c%)) - (let ([woody (new woody/hat+c%)]) - (set-field! hat-location woody 'under-the-dresser))] + (eval:error (get-field hat-location (new woody/hat+c%))) + (eval:error + (let ([woody (new woody/hat+c%)]) + (set-field! hat-location woody 'under-the-dresser)))] } @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 contract @racket[any/c] (but it is checked more efficiently). - @defexamples[#:eval - class-eval - (define woody/init-hat% - (class woody% - (init init-hat-location) - (field [hat-location init-hat-location]) - (define/public (lose-hat) (set! hat-location 'lost)) - (define/public (find-hat) (set! hat-location 'on-head)) - (super-new))) - (define/contract woody/init-hat+c% - (class/c [draw (->m symbol? string?)] - [lose-hat (->m void?)] - [find-hat (->m void?)] - (init [init-hat-location (or/c 'on-head 'lost)]) - (field [hat-location (or/c 'on-head 'lost)])) - woody/init-hat%) + @examples[#:eval class-eval + (eval:no-prompt + (define woody/init-hat% + (class woody% + (init init-hat-location) + (field [hat-location init-hat-location]) + (define/public (lose-hat) (set! hat-location 'lost)) + (define/public (find-hat) (set! hat-location 'on-head)) + (super-new))) + (define/contract woody/init-hat+c% + (class/c [draw (->m symbol? string?)] + [lose-hat (->m void?)] + [find-hat (->m void?)] + (init [init-hat-location (or/c 'on-head 'lost)]) + (field [hat-location (or/c 'on-head 'lost)])) + woody/init-hat%)) (get-field hat-location (new woody/init-hat+c% [init-hat-location 'lost])) - (get-field hat-location - (new woody/init-hat+c% - [init-hat-location 'slinkys-mouth]))] + (eval:error + (get-field hat-location + (new woody/init-hat+c% + [init-hat-location 'slinkys-mouth])))] } @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 for dynamic dispatch. - @defexamples[#:eval - class-eval + @examples[#:eval class-eval (new (class woody+c% (inherit draw) (super-new) (printf "woody sez: “~a”\n" (draw "evil dr porkchop")))) - (define/contract woody+c-inherit% - (class/c (inherit [draw (->m symbol? string?)])) - woody+c%) - (new (class woody+c-inherit% - (inherit draw) - (printf "woody sez: ~a\n" (draw "evil dr porkchop"))))] + (eval:no-prompt + (define/contract woody+c-inherit% + (class/c (inherit [draw (->m symbol? string?)])) + woody+c%)) + (eval:error + (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 @@ -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 be invoked. - @defexamples[#:eval - class-eval - (define/contract woody2+c% - (class/c (super [draw (->m symbol? string?)])) - (class woody% - (define/override draw - (case-lambda - [(a) (super draw a)] - [(a b) (string-append (super draw a) - " and " - (super draw b))])) - (super-new))) + @examples[#:eval class-eval + (eval:no-prompt + (define/contract woody2+c% + (class/c (super [draw (->m symbol? string?)])) + (class woody% + (define/override draw + (case-lambda + [(a) (super draw a)] + [(a b) (string-append (super draw a) + " and " + (super draw b))])) + (super-new)))) (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] doesn't break @racket[draw2]. - @defexamples[#:eval - class-eval - (define/contract woody2+override/c% - (class/c (override [draw (->m symbol? string?)])) - (class woody+c% - (inherit draw) - (define/public (draw2 a b) - (string-append (draw a) - " and " - (draw b))) - (super-new))) + @examples[#:eval class-eval + (eval:no-prompt + (define/contract woody2+override/c% + (class/c (override [draw (->m symbol? string?)])) + (class woody+c% + (inherit draw) + (define/public (draw2 a b) + (string-append (draw a) + " and " + (draw b))) + (super-new))) - (define woody2+broken-draw - (class woody2+override/c% - (define/override (draw x) - 'not-a-string) - (super-new))) - - (send (new woody2+broken-draw) draw2 - 'evil-dr-porkchop - 'zurg)] + (define woody2+broken-draw + (class woody2+override/c% + (define/override (draw x) + 'not-a-string) + (super-new)))) + + (eval:error + (send (new woody2+broken-draw) draw2 + '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. -@defexamples[#:eval class-eval +@examples[#:eval class-eval (object? (new object%)) (object? object%) (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. -@defexamples[#:eval class-eval +@examples[#:eval class-eval (class? object%) (class? (class object% (super-new))) (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. -@defexamples[#:eval class-eval +@examples[#:eval class-eval (interface? (interface () empty cons first rest)) (interface? object%) (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. -@defexamples[#:eval class-eval +@examples[#:eval class-eval (define c% (class object% (super-new) @@ -2448,7 +2478,7 @@ This procedure is similar in spirit to @racket[eq?] but also works properly with contracts (and has a stronger guarantee). -@defexamples[#:eval class-ctc-eval +@examples[#:eval class-ctc-eval (define obj-1 (new object%)) (define obj-2 (new object%)) (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 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=? (new object%) #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 inspectable fields, analogous to @racket[struct->vector]. -@defexamples[#:eval class-eval +@examples[#:eval class-eval (object->vector (new object%)) (object->vector (new (class object% (super-new) @@ -2494,7 +2524,7 @@ inspectable fields, analogous to @racket[struct->vector]. Returns the interface implicitly defined by @racket[class]. -@defexamples[#:eval class-eval +@examples[#:eval class-eval (class->interface object%) ]} @@ -2504,7 +2534,7 @@ Returns the interface implicitly defined by @racket[class]. Returns the interface implicitly defined by the class of @racket[object]. -@defexamples[#:eval class-eval +@examples[#:eval class-eval (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[#f] otherwise. -@defexamples[#:eval class-eval +@examples[#:eval class-eval (define point<%> (interface () get-x get-y)) (define 2d-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 to) @racket[cls], @racket[#f] otherwise. -@defexamples[#:eval class-eval +@examples[#:eval class-eval (subclass? (class object% (super-new)) object%) (subclass? object% (class object% (super-new))) (subclass? object% object%) @@ -2548,7 +2578,7 @@ to) @racket[cls], @racket[#f] otherwise. Returns @racket[#t] if @racket[v] is a class that implements @racket[intf], @racket[#f] otherwise. -@defexamples[#:eval class-eval +@examples[#:eval class-eval (define i<%> (interface () go)) (define c% (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 @racket[intf], @racket[#f] otherwise. -@defexamples[#:eval class-eval +@examples[#:eval class-eval (define point<%> (interface () get-x get-y)) (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] otherwise. -@defexamples[#:eval class-eval +@examples[#:eval class-eval (define i<%> (interface () get-x get-y)) (method-in-interface? 'get-x 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 @racket[define-local-member-name]). -@defexamples[#:eval class-eval +@examples[#:eval class-eval (define i<%> (interface () get-x get-y)) (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] that accepts @racket[cnt] arguments, @racket[#f] otherwise. -@defexamples[#:eval class-eval +@examples[#:eval class-eval (define c% (class object% (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 @racket[define-local-member-name]). -@defexamples[#:eval class-eval +@examples[#:eval class-eval (field-names (new object%)) (field-names (new (class object% (super-new) (field [x 0] [y 0])))) ]} diff --git a/pkgs/racket-doc/scribblings/reference/contracts.scrbl b/pkgs/racket-doc/scribblings/reference/contracts.scrbl index 0b29fdddf8..93888ce6c7 100644 --- a/pkgs/racket-doc/scribblings/reference/contracts.scrbl +++ b/pkgs/racket-doc/scribblings/reference/contracts.scrbl @@ -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 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 (listof number?) (list 1 2 3)) - (define/contract just-one-number - (listof number?) - 11)] + (eval:error + (define/contract just-one-number + (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 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 (non-empty-listof number?) (list 1 2 3)) - (define/contract not-enough-numbers - (non-empty-listof number?) - (list))] + (eval:error + (define/contract not-enough-numbers + (non-empty-listof number?) + (list)))] } @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 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 (list*of number?) (cons 1 (cons 2 3))) - (define/contract not-improper-numbers - (list*of number?) - (list 1 2 3))] + (eval:error + (define/contract not-improper-numbers + (list*of number?) + (list 1 2 3)))] @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 @racket[cons/c] returns a @racket[list-contract?]. -@examples[#:eval (contract-eval) +@examples[#:eval (contract-eval) #:once (define/contract a-pair-of-numbers (cons/c number? number?) (cons 1 2)) - (define/contract not-a-pair-of-numbers - (cons/c number? number?) - (cons #f #t))] + (eval:error + (define/contract not-a-pair-of-numbers + (cons/c number? number?) + (cons #f #t)))] @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 the second case, the reverse is true. -@examples[#:eval (contract-eval) +@examples[#:eval (contract-eval) #:once (define/contract an-ordered-pair-of-reals (cons/dc [hd real?] [tl (hd) (>=/c hd)]) (cons 1 2)) - (define/contract not-an-ordered-pair-of-reals - (cons/dc [hd real?] [tl (hd) (>=/c hd)]) - (cons 2 1))] + (eval:error + (define/contract not-an-ordered-pair-of-reals + (cons/dc [hd real?] [tl (hd) (>=/c hd)]) + (cons 2 1)))] @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 is set, it must match @racket[_in]. -@examples[#:eval (contract-eval) +@examples[#:eval (contract-eval) #:once (define/contract current-snack (parameter/c string?) (make-parameter "potato-chip")) @@ -663,9 +668,10 @@ is set, it must match @racket[_in]. (parameter/c string? baked/c) (make-parameter "turkey" (λ (s) (string-append "roasted " s)))) -(current-snack 'not-a-snack) -(parameterize ([current-dinner "tofurkey"]) - (current-dinner)) +(eval:error (current-snack 'not-a-snack)) +(eval:error + (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 as specified by the @racket[key] and @racket[val] arguments. -@examples[#:eval - (contract-eval) +@examples[#:eval (contract-eval) #:once (define/contract good-hash (hash/c integer? boolean?) (hash 1 #t 2 #f 3 #t)) - (define/contract bad-hash - (hash/c integer? boolean?) - (hash 1 "elephant" - 2 "monkey" - 3 "manatee"))] + (eval:error + (define/contract bad-hash + (hash/c integer? boolean?) + (hash 1 "elephant" + 2 "monkey" + 3 "manatee")))] There are a number of technicalities that control how @racket[hash/c] contracts behave. @@ -703,17 +709,15 @@ behave. a flat contract, and the @racket[key] and @racket[val] arguments must also be flat contracts. -@examples[#:eval - (contract-eval) +@examples[#:eval (contract-eval) #:once (flat-contract? (hash/c integer? boolean?)) (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, as they will not check future mutations to the hash table. -@examples[#:eval - (contract-eval) +@examples[#:eval (contract-eval) #:once (define original-h (make-hasheq)) (define/contract ctc-h (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[flat-contract?]. -@examples[#:eval - (contract-eval) +@examples[#:eval (contract-eval) #:once (flat-contract? (hash/c integer? boolean? #:immutable #t))] If either the domain or the range is a @racket[chaperone-contract?], then the result will be a @racket[chaperone-contract?]. -@examples[#:eval - (contract-eval) +@examples[#:eval (contract-eval) #:once (flat-contract? (hash/c (-> integer? integer?) boolean? #:immutable #t)) (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 @racket[flat-contract?], then the resulting contract can be applied only to @racket[equal?]-based hash tables. -@examples[#:eval - (contract-eval) - (define/contract h - (hash/c (-> integer? integer?) any/c) - (make-hasheq))] +@examples[#:eval (contract-eval) #:once + (eval:error + (define/contract h + (hash/c (-> integer? integer?) any/c) + (make-hasheq)))] Also, when such a @racket[hash/c] contract is applied to a hash table, the result is not @racket[eq?] 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. The default is @racket['chaperone]. - @examples[#:eval - (contract-eval) + @examples[#:eval (contract-eval) #:once (define/contract h (hash/dc [k real?] [v (k) (>=/c k)]) (hash 1 3 2 4)) - (define/contract h - (hash/dc [k real?] [v (k) (>=/c k)]) - (hash 3 1 - 4 2))] + (eval:error + (define/contract h + (hash/dc [k real?] [v (k) (>=/c k)]) + (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 is not @racket[eq?] to the input. -@examples[#:eval (contract-eval) +@examples[#:eval (contract-eval) #:once (define/contract chan (channel/c string?) (make-channel)) (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 @racket[call-with-current-continuation]. -@examples[#:eval (contract-eval) +@examples[#:eval (contract-eval) #:once (define/contract tag (prompt-tag/c (-> number? string?)) (make-continuation-prompt-tag)) - (call-with-continuation-prompt - (lambda () - (number->string - (call-with-composable-continuation - (lambda (k) - (abort-current-continuation tag k))))) - tag - (lambda (k) (k "not a number"))) + (eval:error + (call-with-continuation-prompt + (lambda () + (number->string + (call-with-composable-continuation + (lambda (k) + (abort-current-continuation tag k))))) + 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 an @tech{impersonator} contract. -@examples[#:eval (contract-eval) +@examples[#:eval (contract-eval) #:once (define/contract mark-key (continuation-mark-key/c (-> symbol? (listof symbol?))) (make-continuation-mark-key)) - (with-continuation-mark - mark-key - (lambda (s) (append s '(truffle fudge ganache))) - (let ([mark-value (continuation-mark-set-first - (current-continuation-marks) mark-key)]) - (mark-value "chocolate-bar"))) + (eval:error + (with-continuation-mark + mark-key + (lambda (s) (append s '(truffle fudge ganache))) + (let ([mark-value (continuation-mark-set-first + (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 arguments must all be chaperone contracts. -@defexamples[#:eval (contract-eval) +@examples[#:eval (contract-eval) #:once (define/contract my-evt (evt/c evt?) always-evt) @@ -888,7 +892,7 @@ arguments must all be chaperone contracts. (evt/c number? number?) (alarm-evt (+ (current-inexact-milliseconds) 50))) (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; if they do not, a contract violation is signaled. -@examples[#:eval (contract-eval) +@examples[#:eval (contract-eval) #:once (define/contract (check x y) (parametric->/c [X] (boolean? X . -> . X)) (if (or (not x) (equal? y 'surprise)) 'invalid y)) (check #t 'ok) -(check #f 'ignored) +(eval:error (check #f 'ignored)) (check #t 'surprise) ] } @@ -1589,8 +1593,7 @@ the export. should be reported in terms of the public module instead of the private one. - @examples[#:eval - (contract-eval) + @examples[#:eval (contract-eval) #:once (module private-implementation racket/base (require racket/contract) (define (recip x) (/ 1 x)) @@ -1603,7 +1606,7 @@ the export. (provide (recontract-out recip))) (require 'public) - (recip +nan.0)] + (eval:error (recip +nan.0))] Replacing the use of @racket[recontract-out] with just @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?) (* 660 fr)) (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 @@ -1682,7 +1685,7 @@ positions of the contract. Since the contract boundary is between the definition and the surrounding context, references to @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") (define (printing-int? x) (displayln "I was called") @@ -1692,7 +1695,7 @@ between the definition and the surrounding context, references to (if (zero? n) 1 (* 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 @@ -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 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) (number->string n 2)) (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?) (code:comment "mistake, lst might contain inexact numbers") (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] ...) @@ -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[#:omit-define-values]. -@examples[#:eval (contract-eval) +@examples[#:eval (contract-eval) #:once (define-struct/contract fish ([color number?])) (make-fish 5) -(make-fish #f) +(eval:error (make-fish #f)) (define-struct/contract (salmon fish) ([ocean symbol?])) (make-salmon 5 'atlantic) -(make-salmon 5 #f) -(make-salmon #f 'pacific) +(eval:error (make-salmon 5 #f)) +(eval:error (make-salmon #f 'pacific)) ]} @defform[(invariant-assertion invariant-expr expr)]{ @@ -1750,7 +1753,7 @@ The @racket[define-struct/contract] form only allows a subset of the recursive calls, when an invariant is used on the right-hand side of a definition: - @examples[#:eval + @examples[#:eval furlongs->feet-eval (define furlongss->feets (invariant-assertion @@ -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 327 3))] + (eval:error (furlongss->feets (list 1 327 3)))] @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] can be. - @examples[#:eval - (contract-eval) + @examples[#:eval (contract-eval) #:once (module server racket/base (require racket/contract/base) (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)) (provide servers-fault clients-fault)) (require 'client) - (clients-fault) - (servers-fault)] + (eval:error (clients-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[blame-name] field of the blame record, which is used as the first portion of the error message. -@examples[#:eval - (contract-eval) - (contract integer? #f 'pos 'neg 'timothy #f) - (contract integer? #f 'pos 'neg #f #f)] +@examples[#:eval (contract-eval) #:once + (eval:error (contract integer? #f 'pos 'neg 'timothy #f)) + (eval:error (contract integer? #f 'pos 'neg #f #f))] If specified, @racket[source-location-expr] indicates the source location 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 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 (make-flat-contract #:name 'int/c #:first-order integer?)) (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 "not one") (define int->int/c @@ -2039,12 +2040,12 @@ to determine if this is a contract that accepts only @racket[list?] values. b f '(expected "a function of one argument" given: "~e") f))))))) -(contract int->int/c "not fun" 'positive 'negative) +(eval:error (contract int->int/c "not fun" 'positive 'negative)) (define halve (contract int->int/c (λ (x) (/ x 2)) 'positive 'negative)) (halve 2) -(halve 1/2) -(halve 1) +(eval:error (halve 1/2)) +(eval:error (halve 1)) ] @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). For example, consider this contract violation: - @interaction[#:eval (contract-eval) + @examples[#:label #f #:eval (contract-eval) #:once (define/contract f (list/c (-> integer? integer?)) (list (λ (x) x))) -((car f) #f) +(eval:error ((car f) #f)) ] It shows that the portion of the contract being violated is the first 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 the message that indicates the violation. -@defexamples[#:eval (contract-eval) +@examples[#:eval (contract-eval) #:once (define (show-blame-error blame value message) (string-append "Contract Violation!\n" @@ -2309,8 +2310,8 @@ the message that indicates the violation. (-> integer? integer?) (/ x 2)) (f 2) -(f 1) -(f 1/2) +(eval:error (f 1)) +(eval:error (f 1/2)) ] } @@ -2697,7 +2698,7 @@ are below): This function is conservative, so it may return @racket[#f] when @racket[x] does, in fact, accept fewer values. -@examples[#:eval (contract-eval) +@examples[#:eval (contract-eval) #:once (contract-stronger? integer? integer?) (contract-stronger? (between/c 25 75) (between/c 0 100)) (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 the name @racket[opt/c]. -@examples[#:eval (contract-eval) - (define/contract (f x) - (opt/c '(not-a-contract)) - x) - (define/contract (f x) - (opt/c '(not-a-contract) #:error-name define/contract) - x)] +@examples[#:eval (contract-eval) #:once + (eval:error + (define/contract (f x) + (opt/c '(not-a-contract)) + x)) + (eval:error + (define/contract (f x) + (opt/c '(not-a-contract) #:error-name define/contract) + x))] } diff --git a/pkgs/racket-doc/scribblings/reference/custom-ports.scrbl b/pkgs/racket-doc/scribblings/reference/custom-ports.scrbl index 4cc96f8846..ac690a17ba 100644 --- a/pkgs/racket-doc/scribblings/reference/custom-ports.scrbl +++ b/pkgs/racket-doc/scribblings/reference/custom-ports.scrbl @@ -455,7 +455,7 @@ The arguments implement the port as follows: ;; The port doesn't supply procedures to implement progress events: (port-provides-progress-evts? infinite-ones) -(port-progress-evt infinite-ones) +(eval:error (port-progress-evt infinite-ones)) ;; Non-byte port results: (define infinite-voids @@ -464,7 +464,7 @@ The arguments implement the port as follows: (lambda (s) (lambda args 'void)) (lambda (skip s evt) (lambda args 'void)) void)) -(read-char infinite-voids) +(eval:error (read-char infinite-voids)) (read-char-or-special infinite-voids) ;; This port produces 0, 1, 2, 0, 1, 2, etc., but it is not diff --git a/pkgs/racket-doc/scribblings/reference/custom-write.scrbl b/pkgs/racket-doc/scribblings/reference/custom-write.scrbl index 30bba2b84c..ed0d66af3d 100644 --- a/pkgs/racket-doc/scribblings/reference/custom-write.scrbl +++ b/pkgs/racket-doc/scribblings/reference/custom-write.scrbl @@ -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, so that graph and cycle structure can be represented. -@defexamples[ -(define (tuple-print tuple port mode) - (when mode (write-string "<" port)) - (let ([l (tuple-ref tuple)] - [recur (case mode - [(#t) write] - [(#f) display] - [else (lambda (p port) (print p port mode))])]) - (unless (zero? (vector-length l)) - (recur (vector-ref l 0) port) - (for-each (lambda (e) - (write-string ", " port) - (recur e port)) - (cdr (vector->list l))))) - (when mode (write-string ">" port))) +@examples[ +(eval:no-prompt + (define (tuple-print tuple port mode) + (when mode (write-string "<" port)) + (let ([l (tuple-ref tuple)] + [recur (case mode + [(#t) write] + [(#f) display] + [else (lambda (p port) (print p port mode))])]) + (unless (zero? (vector-length l)) + (recur (vector-ref l 0) port) + (for-each (lambda (e) + (write-string ", " port) + (recur e port)) + (cdr (vector->list l))))) + (when mode (write-string ">" port)))) -(struct tuple (ref) - #:methods gen:custom-write - [(define write-proc tuple-print)]) +(eval:no-prompt + (struct tuple (ref) + #:methods gen:custom-write + [(define write-proc tuple-print)])) (display (tuple #(1 2 "a"))) diff --git a/pkgs/racket-doc/scribblings/reference/define-struct.scrbl b/pkgs/racket-doc/scribblings/reference/define-struct.scrbl index 967813a6f4..3ce4bc3892 100644 --- a/pkgs/racket-doc/scribblings/reference/define-struct.scrbl +++ b/pkgs/racket-doc/scribblings/reference/define-struct.scrbl @@ -3,8 +3,8 @@ racket/generic)) @(define posn-eval (make-base-eval)) -@(interaction-eval #:eval posn-eval - (require racket/match racket/stream (for-syntax racket/base))) +@examples[#:hidden #:eval posn-eval + (require racket/match racket/stream (for-syntax racket/base))] @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)) (error "not a valid temperature")) temp)) - (celsius -275) + (eval:error (celsius -275)) ] @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 (struct circle (radius) #:reflection-name ') (circle 15) - (circle-radius "bad") + (eval:error (circle-radius "bad")) ] 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 (struct square (side) #:omit-define-syntaxes) - (match (square 5) - (code:comment "fails to match because syntax is omitted") - [(struct square x) x]) + (eval:error + (match (square 5) + (code:comment "fails to match because syntax is omitted") + [(struct square x) x])) (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 @@ -247,20 +248,20 @@ error is reported. If any @racket[field-option] or @racket[struct-option] keyword is repeated, other than @racket[#:property], a syntax error is reported. -@defexamples[ +@examples[ #:eval posn-eval -(struct posn (x y [z #:auto]) - #:auto-value 0 - #:transparent) +(eval:no-prompt + (struct posn (x y [z #:auto #:mutable]) + #:auto-value 0 + #:transparent)) (posn 1 2) (posn? (posn 1 2)) (posn-y (posn 1 2)) -] +(posn-z (posn 1 2)) -@defs+int[ -#:eval posn-eval -[(struct color-posn posn (hue) #:mutable) - (define cp (color-posn 1 2 "blue"))] +(eval:no-prompt + (struct color-posn posn (hue) #:mutable) + (define cp (color-posn 1 2 "blue"))) (color-posn-hue cp) cp (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 @racket[field-id]. -@defexamples[ +@examples[ #:eval posn-eval -(struct mood-procedure (base rating) - #:property prop:procedure (struct-field-index base)) -(define happy+ (mood-procedure add1 10)) +(eval:no-prompt + (struct mood-procedure (base rating) + #:property prop:procedure (struct-field-index base)) + (define happy+ (mood-procedure add1 10))) (happy+ 2) (mood-procedure-rating happy+) ]} @@ -305,11 +307,12 @@ provided. This form is provided for backwards compatibility; @racket[struct] is preferred. -@defexamples[ +@examples[ #:eval posn-eval -(define-struct posn (x y [z #:auto]) - #:auto-value 0 - #:transparent) +(eval:no-prompt + (define-struct posn (x y [z #:auto]) + #:auto-value 0 + #:transparent)) (make-posn 1 2) (posn? (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 that expand to @racket[define-struct]. -@defexamples[ +@examples[ #:eval posn-eval -(define-syntax (define-xy-struct stx) - (syntax-case stx () - [(ds name . rest) - (with-syntax ([orig stx]) - #'(define-struct/derived orig name (x y) . rest))])) +(eval:no-prompt + (define-syntax (define-xy-struct stx) + (syntax-case stx () + [(ds name . rest) + (with-syntax ([orig stx]) + #'(define-struct/derived orig name (x y) . rest))]))) (define-xy-struct posn) (posn-x (make-posn 1 2)) (define-xy-struct posn #:mutable) (set-posn-x! (make-posn 1 2) 0) (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)) ]} @; ---------------------------------------- diff --git a/pkgs/racket-doc/scribblings/reference/dicts.scrbl b/pkgs/racket-doc/scribblings/reference/dicts.scrbl index 97a7fb4103..28345f2bc2 100644 --- a/pkgs/racket-doc/scribblings/reference/dicts.scrbl +++ b/pkgs/racket-doc/scribblings/reference/dicts.scrbl @@ -1,8 +1,8 @@ #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)) -@(interaction-eval #:eval dict-eval (require racket/dict racket/generic)) +@examples[#:hidden #:eval dict-eval (require racket/dict racket/generic)] @title[#:tag "dicts"]{Dictionaries} @@ -200,12 +200,12 @@ result: @examples[ #:eval dict-eval (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 '((a . "apple") (b . "banana")) 'b) (dict-ref #("apple" "banana") 1) (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?))] @@ -461,10 +461,10 @@ Supported for any @racket[dict] that implements @racket[dict-ref] and @examples[ #: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) (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) ]} @@ -486,7 +486,7 @@ Supported for any @racket[dict] that implements @racket[dict-ref] and @examples[ #:eval dict-eval (define h (make-hash)) -(dict-update! h 'a add1) +(eval:error (dict-update! h 'a add1)) (dict-update! h 'a add1 0) h (define v (vector #f #f #f)) @@ -512,7 +512,7 @@ Supported for any @racket[dict] that implements @racket[dict-ref] and @examples[ #: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 . "apple") (b . "beer")) 'b string-length) ]} diff --git a/pkgs/racket-doc/scribblings/reference/evts.scrbl b/pkgs/racket-doc/scribblings/reference/evts.scrbl index 0e810e41ef..02808a0265 100644 --- a/pkgs/racket-doc/scribblings/reference/evts.scrbl +++ b/pkgs/racket-doc/scribblings/reference/evts.scrbl @@ -1,6 +1,5 @@ #lang scribble/doc @(require scribble/struct - scribble/eval "mz.rkt" (for-label racket/async-channel)) diff --git a/pkgs/racket-doc/scribblings/reference/exns.scrbl b/pkgs/racket-doc/scribblings/reference/exns.scrbl index 9b43d8b07e..316d506bc0 100644 --- a/pkgs/racket-doc/scribblings/reference/exns.scrbl +++ b/pkgs/racket-doc/scribblings/reference/exns.scrbl @@ -103,7 +103,7 @@ exception handler obtains control, and the handler itself is (+ 5 (raise (make-my-exception "failed" (current-continuation-marks))))) -(raise 'failed #t) +(eval:error (raise 'failed #t)) ]} @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. @examples[ -(error 'failed) -(error "failed" 23 'pizza (list 1 2 3)) -(error 'method-a "failed because ~a" "no argument supplied") +(eval:error (error 'failed)) +(eval:error (error "failed" 23 'pizza (list 1 2 3))) +(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)) (raise-argument-error 'feed-machine "integer?" bits) "fed the machine")) -(feed-machine 'turkey) +(eval:error (feed-machine 'turkey)) (define (feed-cow animal) (if (not (eq? animal 'cow)) (raise-argument-error 'feed-cow "'cow" animal) "fed the cow")) -(feed-cow 'turkey) +(eval:error (feed-cow 'turkey)) (define (feed-animals cow sheep goose cat) (if (not (eq? goose 'goose)) (raise-argument-error 'feed-animals "'goose" 2 cow sheep goose cat) "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]). @examples[ + (eval:error (raise-arguments-error 'eat "fish is smaller than its given meal" "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. @examples[ -(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) -(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" "starting " 5 #(1 2 3 4) 0 3)) +(eval:error (raise-range-error 'vector-ref "vector" "ending " 5 #(1 2 3 4) 0 3)) +(eval:error (raise-range-error 'vector-ref "vector" "" 3 #() 0 -1)) +(eval:error (raise-range-error 'vector-ref "vector" "ending " 1 #(1 2 3 4) 2 3 0)) ]} diff --git a/pkgs/racket-doc/scribblings/reference/fasl.scrbl b/pkgs/racket-doc/scribblings/reference/fasl.scrbl index a440bd731b..84bd774431 100644 --- a/pkgs/racket-doc/scribblings/reference/fasl.scrbl +++ b/pkgs/racket-doc/scribblings/reference/fasl.scrbl @@ -2,7 +2,7 @@ @(require "mz.rkt" (for-label racket/fasl)) @(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} diff --git a/pkgs/racket-doc/scribblings/reference/file-ports.scrbl b/pkgs/racket-doc/scribblings/reference/file-ports.scrbl index 19c1df8ba4..969fea7a46 100644 --- a/pkgs/racket-doc/scribblings/reference/file-ports.scrbl +++ b/pkgs/racket-doc/scribblings/reference/file-ports.scrbl @@ -27,8 +27,8 @@ (delete-file i))))) (clean) (begin0 - (defexamples #:eval my-eval - expr ...) + (examples #:eval my-eval + expr ...) (clean)))])) "") diff --git a/pkgs/racket-doc/scribblings/reference/filesystem.scrbl b/pkgs/racket-doc/scribblings/reference/filesystem.scrbl index b25348c850..93a5f5400e 100644 --- a/pkgs/racket-doc/scribblings/reference/filesystem.scrbl +++ b/pkgs/racket-doc/scribblings/reference/filesystem.scrbl @@ -7,7 +7,9 @@ setup/cross-system)) @(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} @@ -1428,7 +1430,7 @@ and bitwise operations such as @racket[bitwise-ior], and @racket[bitwise-and].} -@(interaction-eval #:eval file-eval (begin - (delete-file filename) - (delete-file (make-lock-file-name filename)))) +@examples[#:hidden #:eval file-eval + (delete-file filename) + (delete-file (make-lock-file-name filename))] @(close-eval file-eval) diff --git a/pkgs/racket-doc/scribblings/reference/fixnums.scrbl b/pkgs/racket-doc/scribblings/reference/fixnums.scrbl index f63da787de..9719bd3925 100644 --- a/pkgs/racket-doc/scribblings/reference/fixnums.scrbl +++ b/pkgs/racket-doc/scribblings/reference/fixnums.scrbl @@ -7,7 +7,7 @@ racket/require)) @(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} diff --git a/pkgs/racket-doc/scribblings/reference/flonums.scrbl b/pkgs/racket-doc/scribblings/reference/flonums.scrbl index 377d66455f..8bb56b69a2 100644 --- a/pkgs/racket-doc/scribblings/reference/flonums.scrbl +++ b/pkgs/racket-doc/scribblings/reference/flonums.scrbl @@ -2,7 +2,7 @@ @(require "mz.rkt" (for-label racket/flonum)) @(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} diff --git a/pkgs/racket-doc/scribblings/reference/for.scrbl b/pkgs/racket-doc/scribblings/reference/for.scrbl index eaff5d42f8..7f2d862d7b 100644 --- a/pkgs/racket-doc/scribblings/reference/for.scrbl +++ b/pkgs/racket-doc/scribblings/reference/for.scrbl @@ -379,10 +379,11 @@ source for all syntax errors. @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:} -(for/digits - [a (in-list '(1 2 3))] - [b (in-list '(4 5 6))] - (+ a b)) +(eval:error + (for/digits + [a (in-list '(1 2 3))] + [b (in-list '(4 5 6))] + (+ a b))) (for/digits ([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)))]) n))])) -(for*/digits - [ds (in-list '((8 3) (1 1)))] - [d (in-list ds)] - d) +(eval:error + (for*/digits + [ds (in-list '((8 3) (1 1)))] + [d (in-list ds)] + d)) (for*/digits ([ds (in-list '((8 3) (1 1)))] diff --git a/pkgs/racket-doc/scribblings/reference/format.scrbl b/pkgs/racket-doc/scribblings/reference/format.scrbl index 7a240c8307..4a5bccf01d 100644 --- a/pkgs/racket-doc/scribblings/reference/format.scrbl +++ b/pkgs/racket-doc/scribblings/reference/format.scrbl @@ -1,7 +1,6 @@ #lang scribble/doc @(require scribble/manual scribble/struct - scribble/eval "mz.rkt" (for-label racket/contract 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 at most @racket[max-width] characters. -@interaction[#:eval the-eval +@examples[#:eval the-eval (~a "north") (~a 'south) (~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[max-width], an exception is raised. -@interaction[#:eval the-eval +@examples[#:eval the-eval (~a "abcde" #:max-width 5) (~a "abcde" #:max-width 4) (~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 the end of @racket[right-pad-string]. -@interaction[#:eval the-eval +@examples[#:eval the-eval (~a "apple" #:min-width 20 #:align 'left) (~a "pear" #:min-width 20 #:align 'left #:right-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 @racket[width] characters long: -@interaction[#:eval the-eval +@examples[#:label #f #:eval the-eval (~a "terse" #: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 marker is @racket["..."]. -@interaction[#:eval the-eval +@examples[#:eval the-eval (~v "north") (~v 'south) (~v #"east") @@ -141,7 +140,7 @@ marker is @racket["..."]. 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)]) (~a "The even numbers in " (~v 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 marker is @racket["..."]. -@interaction[#:eval the-eval +@examples[#:eval the-eval (~s "north") (~s 'south) (~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 marker is @racket["..."]. -@interaction[#:eval the-eval +@examples[#:eval the-eval (~e "north") (~e 'south) (~e #"east") @@ -241,7 +240,7 @@ The optional arguments control number formatting: in positional or exponential notation. If @racket[notation] is a 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 #:notation 'exponential) (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 decimal point are used, and the decimal point is never dropped. -@interaction[#:eval the-eval +@examples[#:eval the-eval (~r pi) (~r pi #:precision 4) (~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 using @racket[pad-string]. -@interaction[#:eval the-eval +@examples[#:eval the-eval (~r 17) (~r 17 #: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 digits of @racket[x]. -@interaction[#:eval the-eval +@examples[#:eval the-eval (~r 17 #: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 prefixed if @racket[x] is negative. - @interaction[#:eval the-eval + @examples[#:eval the-eval (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 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 '+)) ]} @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. - @interaction[#:eval the-eval + @examples[#:eval the-eval (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 negative. - @interaction[#:eval the-eval + @examples[#:eval the-eval (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 prefix and a suffix. - @interaction[#:eval the-eval + @examples[#:eval the-eval (let ([sign-table '(("" " up") "an even " ("" " down"))]) (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 greater than @racket[10], then upper-case letters are used. -@interaction[#:eval the-eval +@examples[#:eval the-eval (~r 100 #:base 7) (~r 4.5 #:base 2) (~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'' @racket[format-exponent]: -@interaction[#:eval the-eval +@examples[#:label #f #:eval the-eval (~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[base] otherwise: -@interaction[#:eval the-eval +@examples[#:label #f #:eval the-eval (~r 1234 #:notation 'exponential) (~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 the resulting string is appended to the significand: -@interaction[#:eval the-eval +@examples[#:label #f #:eval the-eval (~r 1234 #:notation 'exponential #:format-exponent (lambda (e) (format "E~a" e))) ]} diff --git a/pkgs/racket-doc/scribblings/reference/futures.scrbl b/pkgs/racket-doc/scribblings/reference/futures.scrbl index aed4951c54..caa0113072 100644 --- a/pkgs/racket-doc/scribblings/reference/futures.scrbl +++ b/pkgs/racket-doc/scribblings/reference/futures.scrbl @@ -2,7 +2,7 @@ @(require "mz.rkt" (for-label racket/future)) @(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}) @@ -67,7 +67,7 @@ execute through a call to @racket[touch], however. future, the given @racket[thunk] may run speculatively in parallel to other computations, as described above. - @interaction[ + @examples[ #:eval future-eval (let ([f (future (lambda () (+ 1 2)))]) (list (+ 3 4) (touch f))) diff --git a/pkgs/racket-doc/scribblings/reference/generic.scrbl b/pkgs/racket-doc/scribblings/reference/generic.scrbl index 7f0136aa66..2195bc4b25 100644 --- a/pkgs/racket-doc/scribblings/reference/generic.scrbl +++ b/pkgs/racket-doc/scribblings/reference/generic.scrbl @@ -132,7 +132,7 @@ method} called @racket[name] that does not support the @techlink{generic instance} @racket[v]. @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) (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] ...) diff --git a/pkgs/racket-doc/scribblings/reference/hashes.scrbl b/pkgs/racket-doc/scribblings/reference/hashes.scrbl index 227199413c..3a9809f319 100644 --- a/pkgs/racket-doc/scribblings/reference/hashes.scrbl +++ b/pkgs/racket-doc/scribblings/reference/hashes.scrbl @@ -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[(combine/key k v0 v)]. -@defexamples[ +@examples[ #:eval the-eval (hash-union (make-immutable-hash '([1 . one])) (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[(combine/key k v0 v)]. -@defexamples[ +@examples[ #:eval the-eval (define h (make-hash)) h diff --git a/pkgs/racket-doc/scribblings/reference/logging.scrbl b/pkgs/racket-doc/scribblings/reference/logging.scrbl index 170dff5826..1353136daa 100644 --- a/pkgs/racket-doc/scribblings/reference/logging.scrbl +++ b/pkgs/racket-doc/scribblings/reference/logging.scrbl @@ -324,8 +324,8 @@ argument list takes precedence.} @note-lib[racket/logging] @(require (for-label racket/logging)) @(define log-eval (make-base-eval)) -@(interaction-eval #:eval log-eval - (require racket/logging)) +@examples[#:hidden #:eval log-eval + (require racket/logging)] @defproc[(log-level/c [v any/c]) 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 ... ...)]. Returns whatever @racket[proc] returns. -@defexamples[ +@examples[ #:eval log-eval (let ([warning-counter 0]) (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]. Returns whatever @racket[proc] returns. -@defexamples[ +@examples[ #:eval log-eval (let ([my-log (open-output-string)]) (with-logging-to-port my-log diff --git a/pkgs/racket-doc/scribblings/reference/match.scrbl b/pkgs/racket-doc/scribblings/reference/match.scrbl index 73e64e23be..05f59838d5 100644 --- a/pkgs/racket-doc/scribblings/reference/match.scrbl +++ b/pkgs/racket-doc/scribblings/reference/match.scrbl @@ -2,8 +2,8 @@ @(require "mz.rkt" "match-grammar.rkt" racket/match) @(define match-eval (make-base-eval)) -@(interaction-eval #:eval match-eval (require racket/match racket/list)) -@(interaction-eval #:eval match-eval (require (for-syntax racket/base))) +@examples[#:hidden #:eval match-eval (require racket/match racket/list)] +@examples[#:hidden #:eval match-eval (require (for-syntax racket/base))] @title[#:tag "match"]{Pattern Matching} @@ -239,9 +239,9 @@ In more detail, patterns match as follows: @racket[struct] declaration can provide the structure type information. - @defexamples[ + @examples[ #: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) [(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 matching purposes. - @defexamples[#:eval match-eval - (define/match (fact n) - [(0) 1] - [(n) (* n (fact (sub1 n)))]) + @examples[#:eval match-eval + (eval:no-prompt + (define/match (fact n) + [(0) 1] + [(n) (* n (fact (sub1 n)))])) (fact 5) ] The function header may also contain optional or keyword arguments, may have curried arguments, and may also contain a rest argument. - @defexamples[#:eval match-eval - (define/match ((f x) #:y [y '(1 2 3)]) - [((regexp #rx"p+") `(,a 2 3)) a] - [(_ _) #f]) + @examples[#:eval match-eval + (eval:no-prompt + (define/match ((f x) #:y [y '(1 2 3)]) + [((regexp #rx"p+") `(,a 2 3)) a] + [(_ _) #f])) ((f "ape") #:y '(5 2 3)) ((f "dog")) - (define/match (g x y . rst) - [(0 0 '()) #t] - [(5 5 '(5 5)) #t] - [(_ _ _) #f]) + (eval:no-prompt + (define/match (g x y . rst) + [(0 0 '()) #t] + [(5 5 '(5 5)) #t] + [(_ _ _) #f])) (g 0 0) (g 5 5 5 5) (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. For example, to extend the pattern matcher and destructure syntax lists, -@defs+int[ +@examples[#:label #f #:eval match-eval - ((define (syntax-list? x) + (eval:no-prompt + (define (syntax-list? x) (and (syntax? x) (list? (syntax->list x)))) (define-match-expander syntax-list @@ -602,8 +606,7 @@ For example, to extend the pattern matcher and destructure syntax lists, (and (identifier? stx) (free-identifier=? stx keyword)))) (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) [(syntax-list (? or-keyword?) b c) @@ -622,9 +625,10 @@ And here is an example showing how @racket[define-match-expander]-bound identifiers are not treated specially unless they appear in the first position of pattern sequence. -@defs+int[ +@examples[#:label #f #:eval match-eval - ((define-match-expander nil + (eval:no-prompt + (define-match-expander nil (λ (stx) #''()) (λ (stx) #''())) (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 occur in any order. - @defexamples[ + @examples[ #: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) [(struct* tree ([val a] [left (struct* tree ([right #f] [val b]))])) diff --git a/pkgs/racket-doc/scribblings/reference/mz.rkt b/pkgs/racket-doc/scribblings/reference/mz.rkt index 6d58dea556..28f95342b9 100644 --- a/pkgs/racket-doc/scribblings/reference/mz.rkt +++ b/pkgs/racket-doc/scribblings/reference/mz.rkt @@ -2,13 +2,13 @@ (require scribble/struct scribble/manual - scribble/eval + scribble/examples scribble/decode racket/contract "../icons.rkt") (provide (all-from-out scribble/manual) - (all-from-out scribble/eval) + (all-from-out scribble/examples) (all-from-out racket/contract)) (require (for-label racket)) diff --git a/pkgs/racket-doc/scribblings/reference/numbers.scrbl b/pkgs/racket-doc/scribblings/reference/numbers.scrbl index 30647d85da..1ce1061240 100644 --- a/pkgs/racket-doc/scribblings/reference/numbers.scrbl +++ b/pkgs/racket-doc/scribblings/reference/numbers.scrbl @@ -8,7 +8,7 @@ racket/random)) @(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} @@ -193,12 +193,12 @@ number, @racket[#f] otherwise.} @defproc[(even? [n integer?]) boolean?]{ Returns @racket[(zero? (modulo 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))]. -@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] @@ -289,7 +289,7 @@ If @racket[z] is exact @racket[0] and no @racket[w] is exact 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?]{ @@ -307,7 +307,7 @@ Returns @racket[_q] with the same sign as @racket[n] such that If @racket[m] is exact @racket[0], the @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?)]{ @@ -336,7 +336,7 @@ Returns @racket[_q] with the same sign as @racket[m] where If @racket[m] is exact @racket[0], the @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)].} diff --git a/pkgs/racket-doc/scribblings/reference/pairs.scrbl b/pkgs/racket-doc/scribblings/reference/pairs.scrbl index 88b87c44f2..a39319377d 100644 --- a/pkgs/racket-doc/scribblings/reference/pairs.scrbl +++ b/pkgs/racket-doc/scribblings/reference/pairs.scrbl @@ -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) 1) (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?]) @@ -264,8 +265,9 @@ must merely start with a chain of at least @racket[pos] pairs. @mz-examples[ (list-tail (list 1 2 3 4) 2) - (list-ref (cons 1 2) 1) - (list-ref 'not-a-pair 0)]} + (list-tail (cons 1 2) 1) + (eval:error (list-tail (cons 1 2) 2)) + (list-tail 'not-a-pair 0)]} @defproc*[([(append [lst list?] ...) list?] @@ -342,7 +344,7 @@ If the @racket[lst]s are empty, then @racket[#t] is returned. @mz-examples[ (andmap positive? '(1 2 3)) - (andmap positive? '(1 2 a)) + (eval:error (andmap positive? '(1 2 a))) (andmap positive? '(1 -2 a)) (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] @(define list-eval (make-base-eval)) -@(interaction-eval #:eval list-eval - (require racket/list (only-in racket/function negate))) +@examples[#:hidden #:eval list-eval + (require racket/list (only-in racket/function negate))] @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] for which @racket[pred] produces a true value. -@defexamples[ +@examples[ #:eval list-eval (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] produces a true value. -@defexamples[ +@examples[ #:eval list-eval (remf* negative? '(1 -2 3 4 -5)) ] diff --git a/pkgs/racket-doc/scribblings/reference/port-lib.scrbl b/pkgs/racket-doc/scribblings/reference/port-lib.scrbl index 9a854b3456..7f0a3d4403 100644 --- a/pkgs/racket-doc/scribblings/reference/port-lib.scrbl +++ b/pkgs/racket-doc/scribblings/reference/port-lib.scrbl @@ -9,7 +9,7 @@ @section{Port String and List Conversions} @(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)]) (listof any/c)]{ diff --git a/pkgs/racket-doc/scribblings/reference/procedures.scrbl b/pkgs/racket-doc/scribblings/reference/procedures.scrbl index 9815a5a6e2..ac3ee93956 100644 --- a/pkgs/racket-doc/scribblings/reference/procedures.scrbl +++ b/pkgs/racket-doc/scribblings/reference/procedures.scrbl @@ -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, the @exnraise[exn:fail:contract]. -@defexamples[ -(define (f x #:y y #:z [z 10]) - (list x y z)) +@examples[ +(eval:no-prompt + (define (f x #:y y #:z [z 10]) + (list x y z))) (keyword-apply f '(#:y) '(2) '(1)) (keyword-apply f '(#:y #:z) '(2 3) '(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[ (define my+ (procedure-reduce-arity + 2)) (my+ 1 2) -(my+ 1 2 3) +(eval:error (my+ 1 2 3)) ]} @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 @racket[procedure-reduce-keyword-arity] and @racket[procedure-rename]. -@defexamples[ -(define show - (make-keyword-procedure (lambda (kws kw-args . rest) - (list kws kw-args rest)))) +@examples[ +(eval:no-prompt + (define show + (make-keyword-procedure (lambda (kws kw-args . rest) + (list kws kw-args rest))))) (show 1) (show #:init 0 1 2 3 #:extra 4) -(define show2 - (make-keyword-procedure (lambda (kws kw-args . rest) - (list kws kw-args rest)) - (lambda args - (list->vector args)))) +(eval:no-prompt + (define show2 + (make-keyword-procedure (lambda (kws kw-args . rest) + (list kws kw-args rest)) + (lambda args + (list->vector args))))) (show2 1) (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] is @racket[#f]). -@defexamples[ -(define orig-show - (make-keyword-procedure (lambda (kws kw-args . rest) - (list kws kw-args rest)))) -(define show (procedure-reduce-keyword-arity - orig-show 3 '(#:init) '(#:extra #:init))) +@examples[ +(eval:no-prompt + (define orig-show + (make-keyword-procedure (lambda (kws kw-args . rest) + (list kws kw-args rest)))) + (define show (procedure-reduce-keyword-arity + orig-show 3 '(#:init) '(#:extra #:init)))) (show #:init 0 1 2 3 #:extra 4) -(show 1) -(show #:init 0 1 2 3 #:extra 4 #:more 7) +(eval:error (show 1)) +(eval:error (show #:init 0 1 2 3 #:extra 4 #:more 7)) ]} @defstruct[arity-at-least ([value exact-nonnegative-integer?])]{ @@ -452,7 +456,7 @@ property is not associated with a procedure structure type. (apply pairs more))]))) (pairs 1 2 3 4) -(pairs 5)]} +(eval:error (pairs 5))]} @defthing[prop:checked-procedure struct-type-property?]{ @@ -517,7 +521,7 @@ applied.} @note-lib[racket/function] @(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]{ 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 resulting function accepts any arguments (including keyword arguments). -@defexamples[ +@examples[ #: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 'x) -(th1 #:y 'z) -(define th2 (thunk* (define x 1) (printf "~a\n" x))) +(eval:error (th1 'x)) +(eval:error (th1 #:y 'z)) +(eval:no-prompt + (define th2 (thunk* (define x 1) (printf "~a\n" x)))) (th2) (th2 'x) (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 @racket[(and (f x ...) ...)] -@defexamples[ +@examples[ #:eval fun-eval -(define f (conjoin exact? integer?)) +(eval:no-prompt + (define f (conjoin exact? integer?))) (f 1) (f 1.0) (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 @racket[(or (f x ...) ...)] -@defexamples[ +@examples[ #:eval fun-eval -(define f (disjoin exact? integer?)) +(eval:no-prompt + (define f (disjoin exact? integer?))) (f 1) (f 1.0) (f 1/2) diff --git a/pkgs/racket-doc/scribblings/reference/regexps.scrbl b/pkgs/racket-doc/scribblings/reference/regexps.scrbl index 5a218ddc1f..9472e06c95 100644 --- a/pkgs/racket-doc/scribblings/reference/regexps.scrbl +++ b/pkgs/racket-doc/scribblings/reference/regexps.scrbl @@ -240,7 +240,7 @@ returns the source byte string for a @tech{regexp value}. @examples[ (byte-regexp #"ap*le") (object-name #rx#"ap*le") -(byte-regexp "ap*le") +(eval:error (byte-regexp "ap*le")) ]} @defproc[(byte-pregexp [bstr bytes?]) byte-pregexp?]{ diff --git a/pkgs/racket-doc/scribblings/reference/sandbox.scrbl b/pkgs/racket-doc/scribblings/reference/sandbox.scrbl index 45d8b6a43b..03a5655594 100644 --- a/pkgs/racket-doc/scribblings/reference/sandbox.scrbl +++ b/pkgs/racket-doc/scribblings/reference/sandbox.scrbl @@ -6,7 +6,7 @@ racket/gui/dynamic)) @(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} @@ -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 top-level namespace: -@interaction[ +@examples[#:label #f #:eval box-eval -(define base-module-eval - (code:comment @#,t{a module cannot have free variables...}) - (make-evaluator 'racket/base '(define (f) later))) +(eval:error + (define base-module-eval + (code:comment @#,t{a module cannot have free variables...}) + (make-evaluator 'racket/base '(define (f) later)))) (define base-module-eval (make-evaluator 'racket/base '(define (f) later) '(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 some cases you can get the evaluator function available inside the sandboxed code, for example: -@interaction[#:eval box-eval -(let ([e (make-evaluator 'racket/base)]) - (e `(,e 1))) +@examples[#:label #f #:eval box-eval +(eval:error + (let ([e (make-evaluator 'racket/base)]) + (e `(,e 1)))) ] An error will be signaled in such cases. diff --git a/pkgs/racket-doc/scribblings/reference/sequences.scrbl b/pkgs/racket-doc/scribblings/reference/sequences.scrbl index c49ced9fb3..4891e55e13 100644 --- a/pkgs/racket-doc/scribblings/reference/sequences.scrbl +++ b/pkgs/racket-doc/scribblings/reference/sequences.scrbl @@ -26,7 +26,7 @@ vice-versa. @(define sequence-evaluator (let ([evaluator (make-base-eval)]) (evaluator '(require racket/generic racket/list racket/stream racket/sequence - racket/contract)) + racket/contract racket/dict)) evaluator)) @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}, @racket[#f] otherwise. -@interaction[#:eval sequence-evaluator +@examples[#:eval sequence-evaluator (sequence? 42) (sequence? '(a b c)) (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 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)] - 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)] } @@ -184,7 +184,7 @@ each element in the sequence. integers starting with @racket[start], where each element is one more than the preceding element. @speed[in-naturals "integer"] - @interaction[#:eval sequence-evaluator + @examples[#:eval sequence-evaluator (for/list ([k (in-naturals)] [x (in-range 10)]) (list k x))] @@ -197,7 +197,7 @@ each element in the sequence. @info-on-seq["pairs" "lists"] @speed[in-list "list"] - @interaction[#:eval sequence-evaluator + @examples[#:eval sequence-evaluator (for/list ([x (in-list '(3 1 4))]) `(,x ,(* x x)))] } @@ -207,7 +207,7 @@ each element in the sequence. @info-on-seq["mpairs" "mutable lists"] @speed[in-mlist "mutable list"] - @interaction[#:eval sequence-evaluator + @examples[#:eval sequence-evaluator (for/list ([x (in-mlist (mcons "RACKET" (mcons "LANG" '())))]) (string-length x))] } @@ -242,7 +242,7 @@ each element in the sequence. @speed[in-vector "vector"] - @interaction[#:eval sequence-evaluator + @examples[#:eval sequence-evaluator (define (histogram vector-of-words) (define a-hash (make-hash)) (for ([word (in-vector vector-of-words)]) @@ -266,7 +266,7 @@ each element in the sequence. @speed[in-string "string"] - @interaction[#:eval sequence-evaluator + @examples[#:eval sequence-evaluator (define (line-count str) (for/sum ([ch (in-string str)]) (if (char=? #\newline ch) 1 0))) @@ -288,7 +288,7 @@ each element in the sequence. @speed[in-bytes "byte string"] - @interaction[#:eval sequence-evaluator + @examples[#:eval sequence-evaluator (define (has-eof? bs) (for/or ([ch (in-bytes bs)]) (= 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. -@defexamples[ +@examples[ #:eval sequence-evaluator (define/contract predicates (sequence/c (-> any/c boolean?)) (in-list (list integer? string->symbol))) -(for ([P predicates]) - (printf "~s\n" (P "cat"))) +(eval:error + (for ([P predicates]) + (printf "~s\n" (P "cat")))) (define/contract numbers&strings (sequence/c number? string?) (in-dict (list (cons 1 "one") (cons 2 "two") (cons 3 'three)))) -(for ([(N S) numbers&strings]) - (printf "~s: ~a\n" N S)) +(eval:error + (for ([(N S) numbers&strings]) + (printf "~s: ~a\n" N S))) (define/contract a-sequence (sequence/c #:min-count 2 char?) "x") -(for ([x a-sequence] - [i (in-naturals)]) - (printf "~a is ~a\n" i x)) +(eval:error + (for ([x a-sequence] + [i (in-naturals)]) + (printf "~a is ~a\n" i x))) ] } @@ -1202,11 +1205,12 @@ values from the generator. literal, exact, non-negative integer. @examples[#:eval generator-eval - (let ([g (in-generator - (let loop ([n 3]) - (unless (zero? n) (yield n (add1 n)) (loop (sub1 n)))))]) - (let-values ([(not-empty? next) (sequence-generate g)]) - (let loop () (when (not-empty?) (next) (loop))) 'done)) + (eval:error + (let ([g (in-generator + (let loop ([n 3]) + (unless (zero? n) (yield n (add1 n)) (loop (sub1 n)))))]) + (let-values ([(not-empty? next) (sequence-generate g)]) + (let loop () (when (not-empty?) (next) (loop))) 'done))) (let ([g (in-generator #:arity 2 (let loop ([n 3]) (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] with a stop-value known for the generator: - @interaction[#:eval generator-eval + @examples[#:label #f #:eval generator-eval (define abc-generator (generator () (for ([x '(a b c)]) (yield x)))) diff --git a/pkgs/racket-doc/scribblings/reference/serialization.scrbl b/pkgs/racket-doc/scribblings/reference/serialization.scrbl index 980bdd5dc2..2962dc1db5 100644 --- a/pkgs/racket-doc/scribblings/reference/serialization.scrbl +++ b/pkgs/racket-doc/scribblings/reference/serialization.scrbl @@ -2,7 +2,7 @@ @(require "mz.rkt" racket/serialize (for-label racket/serialize racket/fasl)) @(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} diff --git a/pkgs/racket-doc/scribblings/reference/sets.scrbl b/pkgs/racket-doc/scribblings/reference/sets.scrbl index 875c189a93..f14c27b0ab 100644 --- a/pkgs/racket-doc/scribblings/reference/sets.scrbl +++ b/pkgs/racket-doc/scribblings/reference/sets.scrbl @@ -3,7 +3,7 @@ @title[#:tag "sets"]{Sets} @(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 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 (set 1 2) (set 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?]{ @@ -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 2 3)) (set=? (seteq 1 2) (mutable-seteq 2 1)) -(set=? (seteq 1 2) (seteqv 1 2)) (code:comment "Sets of different types cannot -be compared.") +(eval:error (set=? (seteq 1 2) (seteqv 1 2))) (code:comment "Sets of different types cannot be compared") ] } diff --git a/pkgs/racket-doc/scribblings/reference/shared.scrbl b/pkgs/racket-doc/scribblings/reference/shared.scrbl index e2fad691e4..ecdcfd3cfc 100644 --- a/pkgs/racket-doc/scribblings/reference/shared.scrbl +++ b/pkgs/racket-doc/scribblings/reference/shared.scrbl @@ -3,7 +3,7 @@ @(define shared-eval (make-base-eval)) -@(interaction-eval #:eval shared-eval (require racket/shared)) +@examples[#:hidden #:eval shared-eval (require racket/shared)] @(define maker (make-element #f (list @@ -125,11 +125,11 @@ that can be created via mutation). (shared ([a (cons 1 b)] [b 7]) a) -(shared ([a a]) (code:comment @#,t{no indirection...}) - a) -(shared ([a (cons 1 b)] (code:comment @#,t{@racket[b] is early...}) - [b a]) - a) +(eval:error (shared ([a a]) (code:comment @#,t{no indirection...}) + a)) +(eval:error (shared ([a (cons 1 b)] (code:comment @#,t{@racket[b] is early...}) + [b a]) + a)) (shared ([a (mcons 1 b)] (code:comment @#,t{@racket[b] is patchable...}) [b a]) a) diff --git a/pkgs/racket-doc/scribblings/reference/splicing.scrbl b/pkgs/racket-doc/scribblings/reference/splicing.scrbl index d657dfd1c6..1d24b111af 100644 --- a/pkgs/racket-doc/scribblings/reference/splicing.scrbl +++ b/pkgs/racket-doc/scribblings/reference/splicing.scrbl @@ -2,9 +2,9 @@ @(require "mz.rkt" (for-label racket/splicing racket/stxparam racket/local)) @(define splice-eval (make-base-eval)) -@interaction-eval[#:eval splice-eval (require racket/splicing - racket/stxparam - (for-syntax racket/base))] +@examples[#:hidden #:eval splice-eval (require racket/splicing + racket/stxparam + (for-syntax racket/base))] @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)]) (define o one)) o -one +(eval:error one) ] 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[ #:eval splice-eval -(splicing-letrec ([x bad] - [bad 1]) - x)] +(eval:error + (splicing-letrec ([x bad] + [bad 1]) + x))] 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 diff --git a/pkgs/racket-doc/scribblings/reference/string-ports.scrbl b/pkgs/racket-doc/scribblings/reference/string-ports.scrbl index 0c53ddba87..9894e605ca 100644 --- a/pkgs/racket-doc/scribblings/reference/string-ports.scrbl +++ b/pkgs/racket-doc/scribblings/reference/string-ports.scrbl @@ -2,7 +2,7 @@ @(require "mz.rkt") @(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} diff --git a/pkgs/racket-doc/scribblings/reference/strings.scrbl b/pkgs/racket-doc/scribblings/reference/strings.scrbl index 9439bb362a..97427350e8 100644 --- a/pkgs/racket-doc/scribblings/reference/strings.scrbl +++ b/pkgs/racket-doc/scribblings/reference/strings.scrbl @@ -378,7 +378,7 @@ allocated string).} @note-lib[racket/string] @(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?]{ @; Note: this is exactly the same description as the one for append* diff --git a/pkgs/racket-doc/scribblings/reference/struct.scrbl b/pkgs/racket-doc/scribblings/reference/struct.scrbl index 4fc17890de..1d0aa270ba 100644 --- a/pkgs/racket-doc/scribblings/reference/struct.scrbl +++ b/pkgs/racket-doc/scribblings/reference/struct.scrbl @@ -197,52 +197,52 @@ The result of @racket[make-struct-type] is five values: @examples[ #:eval struct-eval -(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)) + +(eval:no-prompt + (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 2) (define a-first (make-struct-field-accessor a-ref 0)) (a-first an-a) -] -@interaction[ -#:eval struct-eval -(define-values (struct:b make-b b? b-ref b-set!) - (make-struct-type 'b struct:a 1 2 'b-uninitialized)) -(define a-b (make-b 'x 'y 'z)) +(eval:no-prompt + (define-values (struct:b make-b b? b-ref b-set!) + (make-struct-type 'b struct:a 1 2 'b-uninitialized)) + (define a-b (make-b 'x 'y 'z))) + (a-ref a-b 1) (a-ref a-b 2) (b-ref a-b 0) (b-ref a-b 1) (b-ref a-b 2) -] -@interaction[ -#:eval struct-eval -(define-values (struct:c make-c c? c-ref c-set!) - (make-struct-type - 'c struct:b 0 0 #f null (make-inspector) #f null - (code:comment #,(t "guard checks for a number, and makes it inexact")) - (lambda (a1 a2 b1 name) - (unless (number? a2) - (error (string->symbol (format "make-~a" name)) - "second field must be a number")) - (values a1 (exact->inexact a2) b1)))) -(make-c 'x 'y 'z) +(eval:no-prompt + (define-values (struct:c make-c c? c-ref c-set!) + (make-struct-type + 'c struct:b 0 0 #f null (make-inspector) #f null + (code:comment #,(t "guard checks for a number, and makes it inexact")) + (lambda (a1 a2 b1 name) + (unless (number? a2) + (error (string->symbol (format "make-~a" name)) + "second field must be a number")) + (values a1 (exact->inexact a2) b1))))) + +(eval:error (make-c 'x 'y 'z)) (define a-c (make-c 'x 2 'z)) (a-ref a-c 1) -]} -@interaction[ -#:eval struct-eval -(define p1 #s(p a b c)) -(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))) +(eval:no-prompt + (define p1 #s(p a b c)) + (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)))) + (p? p1) (p-ref p1 0) (make-p 'x 'y 'z) -] +]} @defproc[(make-struct-field-accessor [accessor-proc struct-accessor-procedure?] [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 #s(pre 1 2 3)) (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 'skip) (struct->list 'not-a-struct #:on-opaque 'return-false) diff --git a/pkgs/racket-doc/scribblings/reference/stx-comp.scrbl b/pkgs/racket-doc/scribblings/reference/stx-comp.scrbl index 762da318bf..8b4478c889 100644 --- a/pkgs/racket-doc/scribblings/reference/stx-comp.scrbl +++ b/pkgs/racket-doc/scribblings/reference/stx-comp.scrbl @@ -2,7 +2,7 @@ @(require "mz.rkt") @(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} diff --git a/pkgs/racket-doc/scribblings/reference/stx-ops.scrbl b/pkgs/racket-doc/scribblings/reference/stx-ops.scrbl index 9ba322a818..3616be07a1 100644 --- a/pkgs/racket-doc/scribblings/reference/stx-ops.scrbl +++ b/pkgs/racket-doc/scribblings/reference/stx-ops.scrbl @@ -1,5 +1,5 @@ #lang scribble/doc -@(require "mz.rkt" scribble/eval) +@(require "mz.rkt") @(define stx-eval (make-base-eval)) @(stx-eval '(require (for-syntax racket/base))) diff --git a/pkgs/racket-doc/scribblings/reference/stx-param.scrbl b/pkgs/racket-doc/scribblings/reference/stx-param.scrbl index d17a3d02b5..d6ae7ab106 100644 --- a/pkgs/racket-doc/scribblings/reference/stx-param.scrbl +++ b/pkgs/racket-doc/scribblings/reference/stx-param.scrbl @@ -1,6 +1,5 @@ #lang scribble/doc @(require "mz.rkt" - scribble/eval (for-label racket/stxparam racket/stxparam-exptime racket/splicing)) @(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 the target's value. -@defexamples[#:eval the-eval +@examples[#:eval the-eval (define-syntax-parameter current-class #f) (define-syntax-parameter yield (make-rename-transformer #'abort)) (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 the target's value. -@defexamples[#:eval the-eval +@examples[#:eval the-eval (define-syntax-parameter abort (syntax-rules ())) (define-syntax forever diff --git a/pkgs/racket-doc/scribblings/reference/stx-trans.scrbl b/pkgs/racket-doc/scribblings/reference/stx-trans.scrbl index b8816f82f5..e8d6832c95 100644 --- a/pkgs/racket-doc/scribblings/reference/stx-trans.scrbl +++ b/pkgs/racket-doc/scribblings/reference/stx-trans.scrbl @@ -9,7 +9,7 @@ syntax/intdef)) @(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 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 (define-syntax (transformer-2 stx) (syntax-local-value #'something-else (λ () (error "no binding")))) - (transformer-2) + (eval:error (transformer-2)) ] @examples[#:eval stx-eval (define-syntax nachos #'(printf "nachos~n")) diff --git a/pkgs/racket-doc/scribblings/reference/syntax-model.scrbl b/pkgs/racket-doc/scribblings/reference/syntax-model.scrbl index d3cf4cb2af..0b9fdab175 100644 --- a/pkgs/racket-doc/scribblings/reference/syntax-model.scrbl +++ b/pkgs/racket-doc/scribblings/reference/syntax-model.scrbl @@ -2,7 +2,7 @@ @(require scribble/struct "mz.rkt" (for-syntax mzscheme)) @(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} @@ -893,7 +893,7 @@ bucket-2 (define (odd x) (if (zero? x) #f (even (sub1 x)))) (define (even x) (if (zero? x) #t (odd (sub1 x)))) (odd 17))])) -(defs-and-uses/fail) +(eval:error (defs-and-uses/fail)) (define-syntax defs-and-uses (syntax-rules () diff --git a/pkgs/racket-doc/scribblings/reference/syntax-util.scrbl b/pkgs/racket-doc/scribblings/reference/syntax-util.scrbl index d4125b3507..50a482d9e6 100644 --- a/pkgs/racket-doc/scribblings/reference/syntax-util.scrbl +++ b/pkgs/racket-doc/scribblings/reference/syntax-util.scrbl @@ -36,13 +36,13 @@ in the argument list are automatically converted to symbols. [(make-pred name) (format-id #'name "~a?" (syntax-e #'name))])) (make-pred pair) -(make-pred none-such) +(eval:error (make-pred none-such)) (define-syntax (better-make-pred stx) (syntax-case stx () [(better-make-pred name) (format-id #'name #:source #'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 @@ -108,9 +108,10 @@ is prefixed with the special form name as described under @racket[current-syntax-context]. @examples[#:eval the-eval -(wrong-syntax #'here "expected ~s" 'there) -(parameterize ([current-syntax-context #'(look over here)]) - (wrong-syntax #'here "expected ~s" 'there)) +(eval:error (wrong-syntax #'here "expected ~s" 'there)) +(eval:error + (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 diff --git a/pkgs/racket-doc/scribblings/reference/syntax.scrbl b/pkgs/racket-doc/scribblings/reference/syntax.scrbl index 4308848967..9e2a88413b 100644 --- a/pkgs/racket-doc/scribblings/reference/syntax.scrbl +++ b/pkgs/racket-doc/scribblings/reference/syntax.scrbl @@ -282,7 +282,7 @@ form. See also @racket[module-compiled-language-info], See also @secref["module-eval-model"] and @secref["mod-parse"]. -@defexamples[#:eval (syntax-eval) +@examples[#:eval (syntax-eval) #:once (module duck racket/base (provide num-eggs quack) (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 error is reported. - @defexamples[#:eval (syntax-eval) + @examples[#:eval (syntax-eval) #:once (require (only-in racket/tcp tcp-listen [tcp-accept my-accept])) tcp-listen my-accept - tcp-accept + (eval:error tcp-accept) ]} @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 reported. - @defexamples[#:eval (syntax-eval) + @examples[#:eval (syntax-eval) #:once (require (except-in racket/tcp tcp-listen)) tcp-accept - tcp-listen + (eval:error tcp-listen) ]} @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 identifiers before prefixing. - @defexamples[#:eval (syntax-eval) + @examples[#:eval (syntax-eval) #:once (require (prefix-in tcp: racket/tcp)) tcp:tcp-accept 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] describes, a syntax error is reported. - @defexamples[#:eval (syntax-eval) + @examples[#:eval (syntax-eval) #:once (require (rename-in racket/tcp (tcp-accept accept) (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 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) (only-in racket/tcp tcp-listen))) 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 transform phase: - @interaction[#:eval meta-in-eval + @examples[#:label #f #:eval meta-in-eval (module nest racket (provide (for-syntax meta-eggs) (for-meta 1 meta-chicks) @@ -604,13 +604,13 @@ bindings of each @racket[require-spec] are visible for expanding later #'(void)) (desc) - num-eggs + (eval:error num-eggs) ] The following example imports only bindings at @tech{phase level} 0, the normal phase. - @interaction[#:eval meta-in-eval + @examples[#:label #f #:eval meta-in-eval (require (only-meta-in 0 'nest)) 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 combination that involves @racket[#f] produces @racket[#f]. - @defexamples[#:eval (syntax-eval) + @examples[#:eval (syntax-eval) #:once (module nest racket (provide num-eggs) (define num-eggs 2)) @@ -894,7 +894,7 @@ level} 0 are imported. (let () (local-require racket/control) fcontrol) - fcontrol + (eval:error fcontrol) ]} @@ -944,7 +944,7 @@ as follows. identifier must match (otherwise, the external name could be ambiguous). - @defexamples[#:eval (syntax-eval) + @examples[#:eval (syntax-eval) #:once (module nest racket (provide num-eggs) (define num-eggs 2)) @@ -968,7 +968,7 @@ as follows. macro-introduced imports are not re-exported, unless the @racket[(all-defined-out)] form was introduced at the same time. - @defexamples[#:eval (syntax-eval) + @examples[#:eval (syntax-eval) #:once (module nest racket (provide (all-defined-out)) (define num-eggs 2)) @@ -987,7 +987,7 @@ as follows. macro-introduced imports are not re-exported, unless the @racket[module-path] was introduced at the same time. - @defexamples[#:eval (syntax-eval) + @examples[#:eval (syntax-eval) #:once (module nest racket (provide num-eggs) (define num-eggs 2)) @@ -1003,13 +1003,13 @@ as follows. the relevant @tech{phase level}. The symbolic name for each export is @racket[export-id] instead @racket[orig-d]. - @defexamples[#:eval (syntax-eval) + @examples[#:eval (syntax-eval) #:once (module nest racket (provide (rename-out [count num-eggs])) (define count 2)) (require 'nest) num-eggs - count + (eval:error count) ]} @defsubform[(except-out provide-spec provide-spec ...)]{ Like the @@ -1019,7 +1019,7 @@ as follows. reported. The symbolic export name information in the latter @racket[provide-spec]s is ignored; only the bindings are used. - @defexamples[#:eval (syntax-eval) + @examples[#:eval (syntax-eval) #:once (module nest racket (provide (except-out (all-defined-out) num-chicks)) @@ -1027,14 +1027,14 @@ as follows. (define num-chicks 3)) (require 'nest) num-eggs - num-chicks + (eval:error num-chicks) ]} @defsubform[(prefix-out prefix-id provide-spec)]{ Like @racket[provide-spec], but with each symbolic export name from @racket[provide-spec] prefixed with @racket[prefix-id]. - @defexamples[#:eval (syntax-eval) + @examples[#:eval (syntax-eval) #:once (module nest racket (provide (prefix-out chicken: num-eggs)) (define num-eggs 2)) @@ -1055,7 +1055,7 @@ as follows. accessor and mutator bindings of the super-type are @italic{not} included by @racket[struct-out] for export. - @defexamples[#:eval (syntax-eval) + @examples[#:eval (syntax-eval) #:once (module nest racket (provide (struct-out egg)) (struct egg (color wt))) @@ -1066,7 +1066,7 @@ as follows. @defsubform[(combine-out provide-spec ...)]{ The union of the @racket[provide-spec]s. - @defexamples[#:eval (syntax-eval) + @examples[#:eval (syntax-eval) #:once (module nest racket (provide (combine-out num-eggs num-chicks)) (define num-eggs 2) @@ -1084,7 +1084,7 @@ as follows. For more details, see @secref["modprotect"]. The @racket[provide-spec] must specify only bindings that are defined within the exporting module. - @examples[#:eval (syntax-eval) + @examples[#:eval (syntax-eval) #:once (module nest racket (provide num-eggs (protect-out num-chicks)) (define num-eggs 2) @@ -1102,7 +1102,7 @@ as follows. (require 'nest) (list num-eggs num-chicks) (weak-eval 'num-eggs) - (weak-eval 'num-chicks) + (eval:error (weak-eval 'num-chicks)) ]} @specsubform[#:literals (for-meta) @@ -1118,7 +1118,7 @@ as follows. @racket[all-from-out] exports bindings imported with a shift by @racket[phase-level]. - @examples[#:eval (syntax-eval) + @examples[#:eval (syntax-eval) #:once (module nest racket (begin-for-syntax (define eggs 2)) @@ -1132,11 +1132,12 @@ as follows. (test-eggs) chickens - (module broken-nest racket - (define eggs 2) - (define chickens 3) - (provide (for-syntax eggs) - chickens)) + (eval:error + (module broken-nest racket + (define eggs 2) + (define chickens 3) + (provide (for-syntax eggs) + chickens))) (module nest2 racket (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 expression (see @secref["regexp"]). -@defexamples[#:eval (syntax-eval) +@examples[#:eval (syntax-eval) #:once (module zoo racket/base (provide tunafish swordfish blowfish monkey lizard ant) @@ -1324,7 +1325,7 @@ Like @racket[require-spec], but including only imports whose names tunafish swordfish blowfish -monkey +(eval:error monkey) ]} @defform[(subtract-in require-spec subtracted-spec ...)]{ @@ -1332,7 +1333,7 @@ monkey Like @racket[require-spec], but omitting those imports that would be imported by one of the @racket[subtracted-spec]s. -@defexamples[#:eval (syntax-eval) +@examples[#:eval (syntax-eval) #:once (module earth racket (provide land sea air) (define land 1) @@ -1350,7 +1351,7 @@ Like @racket[require-spec], but omitting those imports that would be (require racket/require) (require (subtract-in 'solar-system 'earth)) -land +(eval:error land) aliens ]} @@ -1517,7 +1518,7 @@ introduces @racketidfont{#%datum} identifiers. @mz-examples[ (#%datum . 10) (#%datum . x) -(#%datum . #:x) +(eval:error (#%datum . #:x)) ] } @@ -1532,14 +1533,14 @@ expression. @mz-examples[ (#%expression (+ 1 2)) -(#%expression (define x 10)) +(eval:error (#%expression (define x 10))) ] The @racket[#%expression] form is helpful in recursive definition contexts where expanding a subsequent definition can provide compile-time information 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. -@interaction/no-prompt[#:eval meta-in-eval +@examples[#:label #f #:no-prompt #:eval meta-in-eval (define-syntax (define-sym-case stx) (syntax-case stx () [(_ id sym ...) @@ -1548,7 +1549,7 @@ macro that simply records some symbols at compile-time in a given identifier. '(sym ...))]))] 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: -@interaction/no-prompt[#:eval meta-in-eval +@examples[#:label #f #:no-prompt #:eval meta-in-eval (define-syntax (sym-case stx) (syntax-case stx () [(_ 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 a chance to bind @racket[id] and the @racket[sym-case] macro signals an error: -@interaction[#:eval meta-in-eval -(let () - (sym-case land-creatures 'bear - [(bear) 1] - [(fox) 2]) - (define-sym-case land-creatures bear fox)) +@examples[#:label #f #:eval meta-in-eval +(eval:error + (let () + (sym-case land-creatures 'bear + [(bear) 1] + [(fox) 2]) + (define-sym-case land-creatures bear fox))) ] 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 an expression and it moves on to the @racket[define-sym-case] expression. -@interaction[#:eval meta-in-eval +@examples[#:label #f #:eval meta-in-eval (let () (#%expression (sym-case sea-creatures 'whale [(whale) 1] @@ -1740,7 +1742,7 @@ expander introduces @racketidfont{#%app} identifiers. @mz-examples[ (#%app + 1 2) (#%app (lambda (x #:arg y) (list y x)) #:arg 2 1) -(#%app cons) +(eval:error (#%app cons)) ]} @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) [(x) "ex"] [('x) "quoted ex"]) -] -@def+int[ -(define (classify c) - (case (char-general-category c) - [(ll lu lt ln lo) "letter"] - [(nd nl no) "number"] - [else "other"])) + +(eval:no-prompt + (define (classify c) + (case (char-general-category c) + [(ll lu lt ln lo) "letter"] + [(nd nl no) "number"] + [else "other"]))) + (classify #\A) (classify #\1) (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 keyword arguments. -@defexamples[ -(define x 10) +@examples[ +(eval:no-prompt (define x 10)) x -] -@def+int[ -(define (f x) - (+ x 1)) -(f 10) -] -@def+int[ -(define ((f x) [y 20]) - (+ x y)) +(eval:no-prompt + (define (f x) + (+ x 1))) + +(f 10) + +(eval:no-prompt + (define ((f x) [y 20]) + (+ x y))) + ((f 10) 30) ((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 the binding at the same time. -@defexamples[ +@examples[ (define-values () (values)) (define-values (x y z) (values 1 2 3)) 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"]), a @racket[define-syntax] form introduces a local binding. -@defexamples[#:eval (syntax-eval) +@examples[#:eval (syntax-eval) #:once (define-syntax foo (syntax-rules () ((_ a ...) @@ -2490,7 +2494,7 @@ binding; see @secref["macro-introduced-bindings"]. In an @tech{internal-definition context} (see @secref["intdef-body"]), a @racket[define-syntaxes] form introduces local bindings. -@defexamples[#:eval (syntax-eval) +@examples[#:eval (syntax-eval) #:once (define-syntaxes (foo1 foo2 foo3) (let ([transformer1 (lambda (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 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-syntax (make-two syntax-object) (printf "helper is ~a\n" helper) #'2) (make-two) (code:comment @#,t{`helper' is not bound in the runtime phase}) -helper +(eval:error helper) (define-for-syntax (filter-ids 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 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-syntax (bar syntax-object) (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]. -@defexamples[ +@examples[ (define x 12) (set! x (add1 x)) x (let ([x 5]) (set! x (add1 x)) x) -(set! i-am-not-defined 10) +(eval:error (set! i-am-not-defined 10)) ]} @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 (#,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 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)) ] diff --git a/pkgs/racket-doc/scribblings/reference/trace.scrbl b/pkgs/racket-doc/scribblings/reference/trace.scrbl index e0f83fc39e..f5eeb393f4 100644 --- a/pkgs/racket-doc/scribblings/reference/trace.scrbl +++ b/pkgs/racket-doc/scribblings/reference/trace.scrbl @@ -1,6 +1,5 @@ #lang scribble/doc -@(require "mz.rkt" (for-label racket/trace) - scribble/eval) +@(require "mz.rkt" (for-label racket/trace)) @(begin (define ev (make-base-eval)) (ev '(require racket/trace)) diff --git a/pkgs/racket-doc/scribblings/reference/values.scrbl b/pkgs/racket-doc/scribblings/reference/values.scrbl index fb7f3d678f..614a0a42bc 100644 --- a/pkgs/racket-doc/scribblings/reference/values.scrbl +++ b/pkgs/racket-doc/scribblings/reference/values.scrbl @@ -31,5 +31,5 @@ the @racket[call-with-values] call. @examples[ (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)))) ]} diff --git a/pkgs/racket-doc/scribblings/reference/vectors.scrbl b/pkgs/racket-doc/scribblings/reference/vectors.scrbl index 8f8141aa44..9ff98f7df7 100644 --- a/pkgs/racket-doc/scribblings/reference/vectors.scrbl +++ b/pkgs/racket-doc/scribblings/reference/vectors.scrbl @@ -151,8 +151,8 @@ _i)] is the value produced by @racket[(proc _i)]. @note-lib[racket/vector] @(define vec-eval (make-base-eval)) -@(interaction-eval #:eval vec-eval - (require racket/vector)) +@examples[#:hidden #:eval vec-eval + (require racket/vector)] @defproc[(vector-set*! [vec (and/c vector? (not/c immutable?))] [pos exact-nonnegative-integer?]