manual.scrbl (90461B)
1 #lang scribble/doc 2 @(require scribble/manual "utils.rkt" 3 (for-syntax racket/base) 4 (for-label scribble/manual-struct 5 version/utils 6 syntax/quote)) 7 8 @(define lit-ellipses (racket ...)) 9 @(define lit-ellipses+ (racket ...+)) 10 11 @title[#:tag "manual" #:style 'toc]{Manual Forms} 12 13 @defmodulelang[scribble/manual]{The @racketmodname[scribble/manual] 14 language provides all of @racketmodname[scribble/base] plus many 15 additional functions that are specific to writing Racket 16 documentation. It also associates @tech{style properties} with the 17 generated @racket[doc] export to select the default Racket manual 18 style for rendering; see @secref["manual-render-style"] for more 19 information. 20 21 The @racketmodname[scribble/manual] name can also be used as a library 22 with @racket[require], in which case it provides all of the same 23 bindings, but without setting the reader or setting the default 24 rendering format to the Racket manual format.} 25 26 27 @local-table-of-contents[] 28 29 @; ------------------------------------------------------------------------ 30 @section[#:tag "scribble:manual:code"]{Typesetting Code} 31 32 The @racket[codeblock] and @racket[code] forms (see 33 @secref["all-code"]) typeset code verbatim, adding a layer of color to 34 the code based on the same syntax-coloring parsers that are used by 35 DrRacket. Input that is parsed as an identifier is further given a 36 lexical context and hyperlinked via @racket[for-label] imports. 37 38 The @racket[racketblock] and @racket[racket] forms (see 39 @secref["racket-code"]) typeset S-expression code roughly verbatim, 40 but roughly by quoting the source term with 41 @racket[syntax]. Identifiers in the quoted S-expression are 42 hyperlinked via @racket[for-label] imports. 43 44 The two different approaches to typesetting code---@racket[codeblock] 45 and @racket[code] versus @racket[racketblock] and 46 @racket[racket]---have different advantages and disadvantages: 47 48 @itemlist[ 49 50 @item{The @racket[codeblock] and @racket[code] forms work with 51 non-S-expression syntax, and they give authors more control 52 over output (e.g., the literal number @code{2/4} is not 53 normalized to @racket[2/4]). The @racket[codeblock] and 54 @racket[code] forms do not yet support escapes to Scribble 55 element mode, and they cannot adapt spacing based on the width 56 of elements in escapes.} 57 58 @item{The @racket[racketblock] and @racket[racket] forms are more 59 efficient and allow escapes to Scribble element mode. The 60 @racket[racketblock] and @racket[racket] forms are tied to 61 S-expression syntax, however, and they are based on a syntax 62 representation that tends to normalize source terms (e.g., the 63 literal number @code{2/4} is normalized to @racket[2/4]).} 64 65 ] 66 67 @; ---------------------------------------- 68 @subsection[#:tag "all-code"]{@hash-lang[]-Specified Code} 69 70 @defform/subs[(codeblock option ... str-expr ...+) 71 ([option (code:line #:keep-lang-line? keep-expr) 72 (code:line #:indent indent-expr) 73 (code:line #:expand expand-expr) 74 (code:line #:context context-expr) 75 (code:line #:line-numbers line-number-expr) 76 (code:line #:line-number-sep line-number-sep-expr)]) 77 #:contracts ([keep-expr any/c] 78 [indent-expr exact-nonnegative-integer?] 79 [expand-expr (or/c #f (syntax? . -> . syntax?))] 80 [context-expr (or/c #f syntax?)] 81 [line-number-expr (or/c #f exact-nonnegative-integer?)] 82 [line-number-sep-expr exact-nonnegative-integer?])]{ 83 84 Parses the code formed by the strings produced by the 85 @racket[str-expr]s as a Racket module (roughly) and produces a 86 @tech{block} that typesets the code inset via @racket[nested] with the 87 style @racket['code-inset]. See also @racket[typeset-code]. 88 89 The @racket[str-expr]s should normally start with @hash-lang[] to 90 determine the reader syntax for the module, but the resulting 91 ``module'' need not expand or compile---except as needed by 92 @racket[expand-expr]. If @racket[expand-expr] is omitted or produces 93 false, then the input formed by @racket[str-expr] is read until an 94 end-of-file is encountered, otherwise a single form is read from the 95 input. 96 97 When @racket[keep-expr] produces a true value (the default), the first 98 line in the input (which is typically @hash-lang[]) is preserved in 99 the typeset output, otherwise the first line is dropped. The typeset 100 code is indented by the amount specified by @racket[indent-expr], 101 which defaults to @racket[0]. 102 103 When @racket[expand-expr] produces @racket[#f] (which is the default), 104 identifiers in the typeset code are colored and linked based on 105 for-label bindings in the lexical environment of the syntax object 106 provided by @racket[context-expr]. The default @racket[context-expr] 107 has the same lexical context as the first @racket[str-expr]. 108 When @racket[line-number-expr] is true, line number is enabled starting 109 from @racket[line-number-expr], and @racket[line-number-sep-expr] controls 110 the separation (in spaces; defaults to 1) between the line numbers and 111 code. 112 113 When @racket[expand-expr] produces a procedure, it is used to 114 macro-expand the parsed program, and syntax coloring is based on the 115 parsed program. 116 117 For example, 118 119 @codeblock[#:keep-lang-line? #f]|<|{ 120 #lang scribble/manual 121 @codeblock|{ 122 #lang scribble/manual 123 @codeblock{ 124 #lang scribble/manual 125 @title{Hello} 126 } 127 }| 128 }|>| 129 130 produces the typeset result 131 132 @codeblock|{ 133 #lang scribble/manual 134 @codeblock{ 135 #lang scribble/manual 136 @title{Hello} 137 } 138 }| 139 140 } 141 142 143 @defform[(codeblock0 option ... str-expr ...+)]{ 144 145 Like @racket[codeblock], but without the @racket['code-inset] 146 @racket[nested] wrapper.} 147 148 149 @defform/subs[(code option ... str-expr ...+) 150 ([option (code:line #:lang lang-line-expr) 151 (code:line #:expand expand-expr) 152 (code:line #:context context-expr)]) 153 #:contracts ([lang-line-expr (or/c #f string?)] 154 [expand-expr (or/c #f (syntax? . -> . syntax?))] 155 [context-expr (or/c #f syntax?)])]{ 156 157 Like @racket[codeblock], but produces @tech{content} instead of a 158 @tech{block}. No @hash-lang[] line should appear in the string content; 159 instead, it should be provided @racket[#:lang] (as a string 160 without @racket["#lang "]) if needed, and the @hash-lang[] line is always stripped 161 from the output when provided. Also, each newline in @racket[str-expr]s is collapsed 162 along with all surrounding whitespace to a single space. 163 164 For example, 165 166 @codeblock[#:keep-lang-line? #f]|<|{ 167 #lang scribble/manual 168 This is @code[#:lang "at-exp racket"]|{@bold{Hi}}|'s result: 169 @bold{Hi}. 170 }|>| 171 172 produces the typeset result 173 174 @nested[#:style 'inset]{ 175 This is @code[#:lang "at-exp racket"]|{@bold{Hi}}|'s result: 176 @bold{Hi}. 177 } 178 179 } 180 181 @defproc[(typeset-code [#:context context (or/c #f syntax?) #f] 182 [#:expand expand (or/c #f (syntax? . -> . syntax?)) #f] 183 [#:indent indent exact-nonnegative-integer? 2] 184 [#:keep-lang-line? keep? any/c #t] 185 [#:line-numbers line-numbers (or/c #f exact-nonnegative-integer?) #f] 186 [#:line-number-sep line-number-sep exact-nonnegative-integer? 1] 187 [#:block? return-block? any/c #t] 188 [strs string?] ...) 189 (if return-block? block? element?)]{ 190 A function-based version of @racket[codeblock], allowing you to compute the @racket[strs] arguments. 191 192 Unlike @racket[codeblock], the default @racket[context] argument (@racket[#f]) implies that 193 the context is untouched and the @racket[return-block?] argument determines the result 194 structure. The other arguments are treated the same way as @racket[codeblock]. 195 } 196 197 @; ---------------------------------------- 198 @subsection[#:tag "racket-code"]{Racket Code} 199 200 @defform/subs[(racketblock maybe-escape datum ...) 201 ([maybe-escape code:blank 202 (code:line #:escape escape-id)])]{ 203 204 Typesets the @racket[datum] sequence as a table of Racket code 205 inset via @racket[nested] with the style @racket['code-inset]. The 206 source locations of the @racket[datum]s determine the generated 207 layout. For example, 208 209 @racketblock[ 210 (racketblock 211 (define (loop x) 212 (loop (not x)))) 213 ] 214 215 produces the output 216 217 @racketblock[ 218 (define (loop x) 219 (loop (not x))) 220 ] 221 222 with the @racket[(loop (not x))] indented under @racket[define], 223 because that's the way it is idented the use of @racket[racketblock]. 224 Source-location span information is used to preserve @racket[#true] 225 versus @racket[#t] and @racket[#false] versus @racket[#f]; span 226 information is also used heuristically to add @racketvalfont{#i} 227 to the start of an inexact number if its printed form would otherwise 228 be two characters shorter than the source; 229 syntax-object properties are used to preserve square brackets and 230 curly braces versus parentheses; otherwise, using syntax objects tends 231 to normalize the form of S-expression elements, such as rendering 232 @code{2/4} as @racket[2/4]. When source-location information is not 233 available, such as when it is lost by bytecode-compiled macros, 234 spacing is inserted in the same style (within a single line) as the 235 @racket[racket] form. 236 237 @margin-note{See also @racket[quote-syntax/keep-srcloc] for use in a 238 macro to preserve source-location information in a template.} 239 240 In the above example, @racket[define] is typeset as a keyword (in black) 241 and as a hyperlink to @racket[define]'s definition in the reference 242 manual, because this document was built using a @racket[for-label] binding of 243 @racket[define] (in the source) that matches a definition in the 244 reference manual. Similarly, @racket[not] is a hyperlink to its 245 definition in the reference manual. 246 247 Like other forms defined via @racket[define-code], 248 @racket[racketblock] expands identifiers that are bound as 249 @tech{element transformers}. 250 251 An @racket[#:escape] clause specifies an identifier to escape back to 252 an expression that produces an @racket[element]. By default, 253 the escape identifier is @racket[unsyntax]. For example, 254 255 @racketblock[ 256 #:escape nonesuch 257 (racketblock 258 (+ 1 (unsyntax (elem (racket x) (subscript "2"))))) 259 ] 260 261 produces 262 263 @racketblock[ 264 (+ 1 (unsyntax (elem (racket x) (subscript "2")))) 265 ] 266 267 The @racket[escape-id] that defaults to @racket[unsyntax] is recognized via 268 @racket[free-identifier=?], so a binding can hide the escape behavior: 269 270 @RACKETBLOCK[ 271 (racketblock 272 (let ([(UNSYNTAX (racket unsyntax)) #f]) 273 (racketblock 274 (syntax (+ 1 (unsyntax x)))))) 275 ] 276 277 The @racket[RACKETBLOCK] form's default escape is @racket[UNSYNTAX] 278 instead of @racket[unsyntax]. 279 280 A few other escapes are recognized symbolically: 281 282 @itemize[ 283 284 @item{@racket[(#,(indexed-racket code:line) _datum ...)] typesets as the 285 sequence of @racket[_datum]s (i.e., without the 286 @racket[code:line] wrapper).} 287 288 @item{@racket[(#,(indexed-racket code:comment) _content)] typesets like 289 @racket[_content], but colored as a comment and prefixed with a 290 semi-colon. A typical @racket[_content] escapes from 291 Racket-typesetting mode using @racket[unsyntax] and 292 produces a string, an element using @racket[elem], 293 or a paragraph using @racket[t]: 294 295 @verbatim[#:indent 2]|{ 296 (code:comment @#,elem{this is a comment}) 297 }| 298 299 (Note that @litchar|{@#,foo{...}}| reads as 300 @RACKET[(unsyntax (foo "..."))].) 301 } 302 303 @item{@racket[(#,(indexed-racket code:contract) _datum ...)] typesets like 304 the sequence of @racket[_datum]s (including its coloring), but prefixed with a 305 semi-colon.} 306 307 @item{@as-index[@racketidfont{code:blank}] typesets as a blank space.} 308 309 @item{@racket[(#,(indexed-racket code:hilite) _datum)] typesets like 310 @racket[_datum], but with a background highlight.} 311 312 @item{@racket[(#,(indexed-racket code:quote) _datum)] typesets like 313 @racket[(@#,racketidfont{quote} _datum)], but without rendering the 314 @racketidfont{quote} as @litchar{'}.} 315 316 @item{@racketidfont{_}@racket[_id] typesets as @racket[id], but 317 colored as a variable (like @racket[racketvarfont]); this 318 escape applies only if @racketidfont{_}@racket[_id] has no 319 for-label binding and is not specifically colored as a subform 320 non-terminal via @racket[defform], a variable via 321 @racket[defproc], etc.} 322 323 ] 324 325 See also @racketmodname[scribble/comment-reader]. 326 327 @history[#:changed "1.9" @elem{Added heuristic for adding @racketvalfont{#i} to inexact numbers.}]} 328 329 @defform[(RACKETBLOCK maybe-escape datum ...)]{Like @racket[racketblock], but with 330 the default expression escape @racket[UNSYNTAX] instead of @racket[unsyntax].} 331 332 @defform[(racketblock0 maybe-escape datum ...)]{Like @racket[racketblock], but 333 without insetting the code via @racket[nested].} 334 335 @defform[(RACKETBLOCK0 maybe-escape datum ...)]{Like @racket[RACKETBLOCK], but 336 without insetting the code via @racket[nested].} 337 338 @deftogether[( 339 @defform[(racketresultblock maybe-escape datum ...)] 340 @defform[(racketresultblock0 maybe-escape datum ...)] 341 @defform[(RACKETRESULTBLOCK maybe-escape datum ...)] 342 @defform[(RACKETRESULTBLOCK0 maybe-escape datum ...)] 343 )]{ 344 345 Like @racket[racketblock], etc., but colors the typeset text as a 346 result (i.e., a single color with no hyperlinks) instead of code. 347 348 Unlike @racket[racketblock], @racket[racketresultblock] and 349 @racket[RACKETRESULTBLOCK] implement indentation by adding an 350 @racket[(hspace 2)] to the start of each line, instead of using 351 @racket[nested] with the @racket['code-inset] style. To get formatting 352 more like @racket[racketblock] and @racket[racketinput], use 353 @racket[(nested #:style 'code-inset (racketresultblock0 datum ...))] 354 instead of @racket[(racketresultblock datum ...)].} 355 356 @deftogether[( 357 @defform[(racketinput maybe-escape datum ...)] 358 @defform[(RACKETINPUT maybe-escape datum ...)] 359 )]{Like @racket[racketblock] and @racket[RACKETBLOCK], but the 360 @racket[datum]s are typeset after a prompt representing a REPL.} 361 362 @deftogether[( 363 @defform[(racketinput0 maybe-escape datum ...)] 364 @defform[(RACKETINPUT0 maybe-escape datum ...)] 365 )]{ 366 Like @racket[racketinput] and @racket[RACKETINPUT], but 367 without insetting the code via @racket[nested].} 368 369 @defform/subs[(racketmod maybe-file maybe-escape lang datum ...) 370 ([maybe-file code:blank 371 (code:line #:file filename-expr)] 372 [maybe-escape code:blank 373 (code:line #:escape escape-id)])]{ 374 375 Like @racket[racketblock], but the @racket[datum] are typeset inside a 376 @racketmodfont{#lang}-form module whose language is @racket[lang]. 377 378 The source location of @racket[lang] (relative to the body 379 @racket[datum]s) determines the relative positioning of the 380 @racketmodfont{#lang} line in the typeset output. So, line up 381 @racket[lang] with the left end of the content code. 382 383 If @racket[#:file] is provided, then the code block is typeset using 384 @racket[filebox] with @racket[filename-expr] as the filename 385 argument.} 386 387 @defform[(racketmod0 maybe-file maybe-escape lang datum ...)]{ 388 Like @racket[racketmod], but 389 without insetting the code via @racket[nested].} 390 391 @defform[(racket maybe-escape datum ...)]{Like @racket[racketblock], but typeset on 392 a single line and wrapped with its enclosing paragraph, independent of 393 the formatting of @racket[datum].} 394 395 @defform[(RACKET maybe-escape datum ...)]{Like @racket[racket], but with the 396 @racket[UNSYNTAX] escape like @racket[racketblock].} 397 398 @defform[(racketresult maybe-escape datum ...)]{Like @racket[racket], but typeset 399 as a result (i.e., a single color with no hyperlinks).} 400 401 @defform[(racketid maybe-escape datum ...)]{Like @racket[racket], but typeset 402 as an unbound identifier (i.e., no coloring or hyperlinks).} 403 404 @deftogether[( 405 @defform[(schemeblock maybe-escape datum ...)] 406 @defform[(SCHEMEBLOCK maybe-escape datum ...)] 407 @defform[(schemeblock0 maybe-escape datum ...)] 408 @defform[(SCHEMEBLOCK0 maybe-escape datum ...)] 409 @defform[(schemeinput maybe-escape datum ...)] 410 @defform[(schememod lang maybe-escape datum ...)] 411 @defform[(scheme maybe-escape datum ...)] 412 @defform[(SCHEME maybe-escape datum ...)] 413 @defform[(schemeresult maybe-escape datum ...)] 414 @defform[(schemeid maybe-escape datum ...)] 415 )]{ 416 417 Compatibility aliases. Each @racketidfont{scheme...} name is an alias for the 418 corresponding @racketidfont{racket...} binding.} 419 420 @; ------------------------------------------------------------------------ 421 422 @subsection{Preserving Comments} 423 424 @defmodulereader[scribble/comment-reader] 425 426 As a reader module, @racketmodname[scribble/comment-reader] reads a 427 single S-expression that contains @litchar{;}-based comment lines, and 428 it wraps the comments with @racket[code:comment] for use with forms 429 like @racket[racketblock]. More precisely, 430 @racketmodname[scribble/comment-reader] extends the current reader to 431 adjust the parsing of @litchar{;}. 432 433 For example, within a Scribble document that imports 434 @racketmodname[scribble/manual], 435 436 @verbatim[#:indent 2]|{ 437 @#reader scribble/comment-reader 438 (racketblock 439 ;; This is not a pipe 440 (make-pipe) 441 ) 442 }| 443 444 generates 445 446 @#reader scribble/comment-reader 447 (racketblock 448 ;; This is not a pipe 449 (make-pipe) 450 ) 451 452 The initial @litchar["@"] is needed above to shift into S-expression 453 mode, so that @racketmetafont{#reader} is recognized as a reader 454 declaration instead of literal text. Also, the example uses 455 @racket[(racketblock ....)] instead of 456 @racketmetafont["@"]@racket[racketblock]@racketmetafont["["]@racket[....]@racketmetafont["]"] 457 because the @"@"-reader would drop comments within the 458 @racket[racketblock] before giving 459 @racketmodname[scribble/comment-reader] a chance to convert them. 460 461 The implementation of @racketmodname[scribble/comment-reader] uses @racket[unsyntax] to 462 typeset comments. When using @racketmodname[scribble/comment-reader] 463 with, for instance, @racket[RACKETBLOCK], @racket[unsyntax] does not escape, 464 since @racket[RACKETBLOCK] uses @racket[UNSYNTAX] as its escape form. You can 465 declare an escape identifier for 466 @racketmodname[scribble/comment-reader] with @racket[#:escape-id]. For example, 467 468 @verbatim[#:indent 2]|{ 469 @#reader scribble/comment-reader #:escape-id UNSYNTAX 470 (RACKETBLOCK 471 (define-syntax (m stx) 472 (syntax-case stx () 473 [(_ x) 474 ;; Well this was silly 475 #`(#,x)])) 476 ) 477 }| 478 479 generates 480 481 @#reader scribble/comment-reader #:escape-id UNSYNTAX 482 (RACKETBLOCK 483 (define-syntax (m stx) 484 (syntax-case stx () 485 [(_ x) 486 ;; Well this was silly 487 #`(#,x)])) 488 ) 489 490 @; ------------------------------------------------------------------------ 491 @subsection{Code Fonts and Styles} 492 493 @defform*[((racketmodname datum maybe-indirect) 494 (racketmodname ((unsyntax (racket unsyntax)) expr) maybe-indirect)) 495 #:grammar ([maybe-indirect code:blank 496 #:indirect])]{ 497 498 Like @racket[racket], but typeset as a module path and without special 499 treatment of identifiers (such as @racketidfont{code:blank} or identifiers 500 that start with @litchar{_}). If @racket[datum] is an identifier or 501 @racket[expr] produces a symbol, then it is hyperlinked to the module 502 path's definition as created by @racket[defmodule]. 503 504 If @racket[#:indirect] is specified, then the hyperlink is given the 505 @racket['indirect-link] @tech{style property}, which makes the 506 hyperlink's resolution in HTML potentially delayed; see 507 @racket['indirect-link] for @racket[link-element]. 508 509 @history[#:changed "1.21" @elem{Disabled @racket[racket]-style special 510 treatment of identifiers.}]} 511 512 @defform[(racketmodlink datum pre-content-expr ...)]{ 513 Like @racket[racketmodname], but separating the module path to link 514 from the content to be linked. The @racket[datum] module path is always 515 linked, even if it is not an identifier.} 516 517 @defproc[(litchar [str string?] ...) element?]{Typesets @racket[str]s as a 518 representation of literal text. Use this when you have to talk about 519 the individual characters in a stream of text, as when documenting 520 a reader extension.} 521 522 @defproc[(racketfont [pre-content pre-content?] ...) element?]{The 523 same as @racket[(tt pre-content ...)], which applies the @racket['tt] 524 style to immediate strings and symbols among the @racket[pre-content] 525 arguments. Beware that @racket[pre-content] is @racket[decode]d as 526 usual, making @racket[racketfont] a poor choice for typesetting 527 literal code.} 528 529 @defproc[(racketplainfont [pre-content pre-content?] ...) element?]{Applies 530 the @racket['tt] style to @racket[pre-content]. Beware 531 that @racket[pre-content] is @racket[decode]d as usual, making 532 @racket[racketplainfont] a poor choice for typesetting literal code 533 directly but useful for implementing code-formatting functions. 534 535 @history[#:added "1.6"]} 536 537 @defproc[(racketvalfont [pre-content pre-content?] ...) element?]{Like 538 @racket[racketplainfont], but colored as a value.} 539 540 @defproc[(racketresultfont [#:decode? decode? boolean? #t] [pre-content pre-content?] ...) element?]{ 541 Like @racket[racketplainfont], but colored as a REPL result. When 542 @racket[decode?] is @racket[#f], then unlike @racket[racketplainfont], 543 @racket[racketresultfont] avoids @racket[decode]ing its argument.} 544 545 @defproc[(racketidfont [pre-content pre-content?] ...) element?]{Like 546 @racket[racketplainfont], but colored as an identifier.} 547 548 @defproc[(racketvarfont [pre-content pre-content?] ...) element?]{Like 549 @racket[racketplainfont], but colored as a variable (i.e., an argument or 550 sub-form in a procedure being documented).} 551 552 @defproc[(racketkeywordfont [pre-content pre-content?] ...) element?]{Like 553 @racket[racketplainfont], but colored as a syntactic form name.} 554 555 @defproc[(racketparenfont [pre-content pre-content?] ...) element?]{Like 556 @racket[racketplainfont], but colored like parentheses.} 557 558 @defproc[(racketoptionalfont [pre-content pre-content?] ...) element?]{Like 559 @racket[racketplainfont], but colored as optional. 560 @history[#:added "1.36"] 561 } 562 563 @defproc[(racketmetafont [pre-content pre-content?] ...) element?]{Like 564 @racket[racketplainfont], but colored as meta-syntax, such as backquote or 565 unquote.} 566 567 @defproc[(racketcommentfont [pre-content pre-content?] ...) element?]{Like 568 @racket[racketplainfont], but colored as a comment.} 569 570 @defproc[(racketerror [pre-content pre-content?] ...) element?]{Like 571 @racket[racketplainfont], but colored as error-message text.} 572 573 @defproc[(racketmodfont [pre-content pre-content?] ...) element?]{Like 574 @racket[racketplainfont], but colored as module name.} 575 576 @defproc[(racketoutput [pre-content pre-content?] ...) element?]{Like 577 @racket[racketplainfont], but colored as output.} 578 579 @defproc[(procedure [pre-content pre-content?] ...) element?]{Typesets 580 @tech{decode}d @racket[pre-content] as a procedure name in a REPL 581 result (e.g., in typewriter font with a @litchar{#<procedure:} prefix 582 and @litchar{>} suffix.).} 583 584 @defform[(var datum)]{Typesets @racket[datum] as an identifier that is 585 an argument or sub-form in a procedure being documented. Normally, the 586 @racket[defproc] and @racket[defform] arrange for @racket[racket] to 587 format such identifiers automatically in the description of the 588 procedure, but use @racket[var] if that cannot work for some reason.} 589 590 @defform[(svar datum)]{Like @racket[var], but for subform non-terminals 591 in a form definition.} 592 593 @deftogether[( 594 @defform*[((schememodname datum) 595 (schememodname ((unsyntax (racket unsyntax)) expr)))] 596 @defform[(schememodlink datum pre-content-expr ...)] 597 @defproc[(schemefont [pre-content pre-content?] ...) element?] 598 @defproc[(schemevalfont [pre-content pre-content?] ...) element?] 599 @defproc[(schemeresultfont [pre-content pre-content?] ...) element?] 600 @defproc[(schemeidfont [pre-content pre-content?] ...) element?] 601 @defproc[(schemevarfont [pre-content pre-content?] ...) element?] 602 @defproc[(schemekeywordfont [pre-content pre-content?] ...) element?] 603 @defproc[(schemeparenfont [pre-content pre-content?] ...) element?] 604 @defproc[(schemeoptionalfont [pre-content pre-content?] ...) element?] 605 @defproc[(schememetafont [pre-content pre-content?] ...) element?] 606 @defproc[(schemeerror [pre-content pre-content?] ...) element?] 607 @defproc[(schememodfont [pre-content pre-content?] ...) element?] 608 @defproc[(schemeoutput [pre-content pre-content?] ...) element?] 609 )]{ 610 611 Compatibility aliases. Each @racketidfont{scheme...} name is an alias for the 612 corresponding @racketidfont{racket...} binding.} 613 614 @; ------------------------------------------------------------------------ 615 @section[#:tag "doc-modules"]{Documenting Modules} 616 617 @defform/subs[(defmodule maybe-req one-or-multi option ... pre-flow ...) 618 ([maybe-req code:blank 619 (code:line #:require-form content-expr)] 620 [one-or-multi module-spec 621 (code:line #:multi (module-spec ...+))] 622 [module-spec module-path 623 content-expr] 624 [option (code:line #:module-paths (module-path ...)) 625 #:no-declare 626 (code:line #:use-sources (src-module-path ...)) 627 (code:line #:link-target? link-target?-expr) 628 #:indirect 629 #:lang 630 #:reader 631 (code:line #:packages (pkg-expr ...))])]{ 632 633 Produces a sequence of flow elements (in a @racket[splice]) 634 to start the documentation for a module---or for multiple modules, if 635 the @racket[#:multi] form is used. 636 637 Each documented module specified as either a @racket[module-path] (in 638 the sense of @racket[require]), in which case the module path is 639 typeset using @racket[racketmodname], or by a 640 @racket[content-expr]. The latter case is triggered by the presence of 641 a @racket[#:module-paths] clause, which provides a plain 642 @racket[module-path] for each @racket[module-spec], and the plain 643 @racket[module-path] is used for cross-referencing. 644 645 If a @racket[#:require-form] clause is provided and if @racket[#:lang] 646 and @racket[#:reader] are not provided, the given expression produces 647 content to use instead of @racket[require] for the declaration of the 648 module. The @racket[#:require-form] clause is useful to suggest a 649 different way of accessing the module instead of through 650 @racket[require]. 651 652 Besides generating text, unless @racket[#:no-declare] appears as an 653 option, this form expands to a use of @racket[declare-exporting] with 654 @racket[module-path]s; the @racket[#:use-sources] clause, if provided, 655 is propagated to @racket[declare-exporting]. Consequently, 656 @racket[defmodule] should be used at most once in a section without 657 @racket[#:no-declare], though it can be shadowed with 658 @racket[defmodule]s in sub-sections. Use @racket[#:no-declare] form 659 when you want to provide a more specific list of modules (e.g., to 660 name both a specific module and one that combines several modules) via 661 your own @racket[declare-exporting] declaration 662 663 When @racket[#:link-target?] is omitted or specified with an expression that 664 produces a true value, then the @racket[module-path]s are also 665 declared as link targets though a @racket[part-tag-decl] (which means 666 that the @racket[defmodule] form must appear before any 667 sub-parts). These link targets are referenced via 668 @racket[racketmodname], which thus points to the enclosing section, 669 rather than the individual @racket[module-path]s. 670 671 Specifying @racket[#:indirect] normally makes sense only when 672 @racket[#:link-target?] is specified with a @racket[#f] value. Specifying 673 @racket[#:indirect] makes the module path that is displayed (and that 674 normally refers to some other declaration of the module) use 675 @racket[racketmodname] with @racket[#:indirect]. 676 677 If @racket[#:lang] is provided as an option, then the module name is 678 shown after @hash-lang[] (instead of in a @racket[require] form) to 679 indicate that the @racket[module-path]s are suitable for use by either 680 @racket[require] or @hash-lang[]. If the module path for 681 @racket[require] is syntactically different from the @hash-lang[] 682 form, use @racket[#:module-paths] to provide the @racket[require] 683 variant (and make each @racket[module-spec] a @racket[content-expr]). 684 685 If @racket[#:reader] is provided, then the module name is shown after 686 @racketmetafont{#reader} to indicate that the module path is intended 687 for use as a reader module. 688 689 By default, the package (if any) that supplies the documented module 690 is determined automatically, but a set of providing packages can be 691 specified explicitly with @racket[#:packages]. Each @racket[pkg-expr] 692 result is passed on to a function like @racket[tt] for 693 typesetting. Provide an empty sequence after @racket[#:packages] to 694 suppress any package name in the output. Each @racket[pkg-expr] 695 expression is duplicated for a @racket[declare-exporting] form, 696 unless @racket[#:no-declare] is specified. 697 698 Each @racket[option] form can appear at most once, and @racket[#:lang] 699 and @racket[#:reader] are mutually exclusive. 700 701 The @tech{decode}d @racket[pre-flow]s introduce the module, but need 702 not include all of the module content.} 703 704 705 @defform[#:literals (unquote) 706 (declare-exporting module-path/escape ... maybe-pkgs maybe-sources) 707 #:grammar ([maybe-pkgs code:blank 708 (code:line #:packages (pkg-expr ...))] 709 [maybe-sources code:blank 710 (code:line #:use-sources (module-path/escape ...))] 711 [module-path/escape module-path 712 ,module-path-expr])]{ 713 714 Associates the @racket[module-path]s to all bindings defined within the 715 enclosing section, except as overridden by other 716 @racket[declare-exporting] declarations in nested sub-sections. The 717 list of @racket[module-path]s before @racket[#:use-sources] is shown, for 718 example, when the user hovers the mouse over one of the bindings 719 defined within the section. A @racket[unquote]-escaped 720 @racket[,module-path-expr] can be used in place of a 721 @racket[module-path] to compute the module path dynamically. 722 723 More significantly, the first @racket[module-path] before 724 @racket[#:use-sources] plus the @racket[module-path]s after 725 @racket[#:use-sources] determine the binding that is documented by 726 each @racket[defform], @racket[defproc], or similar form within the 727 section that contains the @racket[declare-exporting] declaration: 728 729 @itemize[ 730 731 @item{If no @racket[#:use-sources] clause is supplied, then the 732 documentation applies to the given name as exported by the first 733 @racket[module-path].} 734 735 @item{If @racket[#:use-sources] @racket[module-path]s are supplied, then 736 they are tried in order before the first @racket[module-path]. The 737 @racket[module-path] that provides an export with the same 738 symbolic name and @racket[free-label-identifier=?] to the given 739 name is used as the documented binding. This binding is assumed 740 to be the same as the identifier as exported by the first 741 @racket[module-path] in the @racket[declare-exporting] 742 declaration.} 743 744 ] 745 746 Use @racket[#:use-sources] sparingly, but it is needed when 747 748 @itemlist[ 749 750 @item{bindings are documented as originating from a module 751 @racket[_M], but the bindings are actually re-exported from 752 some module @racket[_P]; and} 753 754 @item{other documented modules also re-export the bindings from 755 @racket[_P], but they are documented as re-exporting from 756 @racket[_M].} 757 758 ] 759 760 For example, the @racket[parameterize] binding of 761 @racketmodname[mzscheme] is documented as re-exported from 762 @racketmodname[racket/base], but @racket[parameterize] happens to be 763 implemented in a private module and re-exported by both 764 @racketmodname[racket/base] and @racketmodname[mzscheme]. Importing 765 @racket[parameterize] from @racketmodname[mzscheme] does not go 766 through @racketmodname[racket/base], so a search for documentation on 767 @racket[parameterize] in @racketmodname[mzscheme] would not 768 automatically connect to the documentation of 769 @racketmodname[racket/base]. To make the connection, the documentation 770 of @racketmodname[racket/base] declares the private module to be a 771 source through @racket[#:use-sources], so that any re-export of 772 @racket[parameterize] from the private module connects to the 773 documentation for @racketmodname[racket/base] (unless a re-export has 774 its own documentation, which would override the automatic connection 775 when searching for documentation). 776 777 The initial @racket[module-path]s sequence can be empty if 778 @racket[module-path]s are given with @racket[#:use-sources]. In that 779 case, the rendered documentation never reports an exporting module for 780 identifiers that are documented within the section, but the 781 @racket[module-path]s in @racket[#:use-sources] provide a binding context 782 for connecting (via hyperlinks) definitions and uses of identifiers. 783 784 Supply @racket[#:packages] to specify the package that provides the 785 declared modules, which is otherwise inferred automatically from the 786 first @racket[module-path]. The package names are used, for example, 787 by @racket[history]. 788 789 The @racket[declare-exporting] form should be used no more than once 790 per section, since the declaration applies to the entire section, 791 although overriding @racket[declare-exporting] forms can appear in 792 sub-sections. 793 794 @history[#:changed "1.1" @elem{Added @racket[#:packages] clause.} 795 #:changed "1.17" @elem{Added support for @racket[,module-path-expr].}]} 796 797 @defform*[[(defmodulelang one-or-multi maybe-sources option ... pre-flow ...) 798 (defmodulelang one-or-multi #:module-path module-path 799 option ... pre-flow ...)]]{ 800 Equivalent to @racket[defmodule] with @racket[#:lang]. The 801 @racket[#:module-path module-path] is provided, it is converted to 802 @racket[#:module-paths (module-path)].} 803 804 @defform[(defmodulereader one-or-multi option ... pre-flow ...)]{ 805 Equivalent to @racket[defmodule] with @racket[#:reader].} 806 807 808 @deftogether[( 809 @defform[(defmodule* maybe-req (module-spec ...+) option ... pre-flow ...)] 810 @defform[(defmodulelang* (module-spec ...+) option ... pre-flow ...)] 811 @defform[(defmodulereader* (module-spec ...+) option ... pre-flow ...)] 812 )]{ 813 Equivalent to @racket[defmodule] variants with @racket[#:multi].} 814 815 @deftogether[( 816 @defform[(defmodule*/no-declare maybe-req (module-spec ...) option ... pre-flow ...)] 817 @defform[(defmodulelang*/no-declare (module-spec ...) option ... pre-flow ...)] 818 @defform[(defmodulereader*/no-declare (module-spec ...) option ... pre-flow ...)] 819 )]{ 820 Equivalent to @racket[defmodule] variants @racket[#:no-declare].} 821 822 @; ------------------------------------------------------------------------ 823 @section[#:tag "doc-forms"]{Documenting Forms, Functions, Structure Types, and Values} 824 825 @defform/subs[(defproc options prototype 826 result-contract-expr-datum 827 maybe-value 828 pre-flow ...) 829 ([prototype (id arg-spec ...) 830 (prototype arg-spec ...)] 831 [arg-spec (arg-id contract-expr-datum) 832 (arg-id contract-expr-datum default-expr) 833 (keyword arg-id contract-expr-datum) 834 (keyword arg-id contract-expr-datum default-expr) 835 ellipses 836 ellipses+] 837 [options (code:line maybe-kind maybe-link maybe-id)] 838 [maybe-kind code:blank 839 (code:line #:kind kind-content-expr)] 840 [maybe-link code:blank 841 (code:line #:link-target? link-target?-expr)] 842 [maybe-id code:blank 843 (code:line #:id [src-id dest-id-expr])] 844 [maybe-value code:blank 845 (code:line #:value value-expr-datum)] 846 [ellipses @#,lit-ellipses] 847 [ellipses+ @#,lit-ellipses+])]{ 848 849 Produces a sequence of flow elements (encapsulated in a 850 @racket[splice]) to document a procedure named @racket[id]. Nesting 851 @racket[prototype]s corresponds to a curried function, as in 852 @racket[define]. Unless @racket[link-target?-expr] is specified 853 and produces @racket[#f], the @racket[id] is indexed, and it also registered so 854 that @racket[racket]-typeset uses of the identifier (with the same 855 for-label binding) are hyperlinked to this documentation. 856 857 Examples: 858 @codeblock[#:keep-lang-line? #f]|{ 859 #lang scribble/manual 860 @defproc[(make-sandwich [ingredients (listof ingredient?)]) 861 sandwich?]{ 862 Returns a sandwich given the right ingredients. 863 } 864 865 @defproc[#:kind "sandwich-maker" 866 (make-reuben [ingredient sauerkraut?] ... 867 [#:veggie? veggie? any/c #f]) 868 sandwich?]{ 869 Produces a reuben given some number of @racket[ingredient]s. 870 871 If @racket[veggie?] is @racket[#f], produces a standard 872 reuben with corned beef. Otherwise, produces a vegetable 873 reuben. 874 } 875 }| 876 877 @doc-render-examples[ 878 @defproc[#:link-target? #f 879 (make-sandwich [ingredients (listof ingredient?)]) 880 sandwich?]{ 881 Returns a sandwich given the right ingredients. 882 } 883 884 @defproc[#:kind "sandwich-maker" 885 #:link-target? #f 886 (make-reuben [ingredient sauerkraut?] ... 887 [#:veggie? veggie? any/c #f]) 888 sandwich?]{ 889 Produces a reuben given some number of @racket[ingredient]s. 890 891 If @racket[veggie?] is @racket[#f], produces a standard 892 reuben with corned beef. Otherwise, produces a vegetable 893 reuben. 894 }] 895 896 When @racket[id] is indexed and registered, 897 a @racket[defmodule] or @racket[declare-exporting] form (or one of the 898 variants) in an enclosing section determines the @racket[id] binding 899 that is being defined. The @racket[id] should also have a for-label 900 binding (as introduced by @racket[(require (for-label ....))]) that 901 matches the definition binding; otherwise, the defined @racket[id] 902 will not typeset correctly within the definition. 903 904 Each @racket[arg-spec] must have one of the following forms: 905 906 @specsubform[(arg-id contract-expr-datum)]{ 907 An argument whose contract is specified by 908 @racket[contract-expr-datum] which is typeset via 909 @racket[racketblock0].} 910 911 @specsubform[(arg-id contract-expr-datum default-expr)]{ 912 Like the previous case, but with a default value. All arguments 913 with a default value must be grouped together, but they can be 914 in the middle of required arguments.} 915 916 @specsubform[(keyword arg-id contract-expr-datum)]{ 917 Like the first case, but for a keyword-based argument.} 918 919 @specsubform[(keyword arg-id contract-expr-datum default-expr)]{ 920 Like the previous case, but with a default 921 value.} 922 923 @specsubform[@#,lit-ellipses]{Any number of the preceding argument. This 924 form is normally used at the end, but keyword-based arguments 925 can sensibly appear afterward. See also the documentation for 926 @racket[append] for a use of @lit-ellipses before the last 927 argument.} 928 929 @specsubform[@#,lit-ellipses+]{One or more of the preceding argument 930 (normally at the end, like @lit-ellipses).} 931 932 The @racket[result-contract-expr-datum] is typeset via 933 @racket[racketblock0], and it represents a contract on the procedure's 934 result. 935 936 The @tech{decode}d @racket[pre-flow] documents the procedure. In this 937 description, references to @svar[arg-id]s using @racket[racket], 938 @racket[racketblock], @|etc| are typeset as procedure arguments. 939 940 The typesetting of all information before the @racket[pre-flow]s 941 ignores the source layout, except that the local formatting is 942 preserved for contracts and default-values expressions. The information 943 is formatted to fit (if possible) in the number of characters specified 944 by the @racket[current-display-width] parameter. 945 946 An optional @racket[#:kind] specification chooses the decorative 947 label, which defaults to @racket["procedure"]. A @racket[#f] 948 result for @racket[kind-content-expr] uses the default, otherwise 949 @racket[kind-content-expr] should produce content in the sense of @racket[content?]. An alternate 950 label should be all lowercase. 951 952 If @racket[#:id [src-id dest-id-expr]] is supplied, then 953 @racket[src-id] is the identifier as it appears in the 954 @racket[prototype] (to be replaced by a defining instance), and 955 @racket[dest-id-expr] produces the identifier to be documented in 956 place of @racket[src-id]. This split between @racket[src-id] and 957 @racket[dest-id-expr] roles is useful for functional abstraction of 958 @racket[defproc]. 959 960 If @racket[#:value value-expr-datum] is given, @racket[value-expr-datum] 961 is typeset using @racket[racketblock0] and included in the documentation. 962 As a service to readers, please use @racket[#:value] to document only 963 simple, short functions. 964 } 965 966 @defform[(defproc* options 967 ([prototype 968 result-contract-expr-datum 969 maybe-value] ...) 970 pre-flow ...)]{ 971 972 Like @racket[defproc], but for multiple cases with the same 973 @racket[id]. Multiple distinct @racket[id]s can also be defined by a 974 single @racket[defproc*], for the case that it's best to document a 975 related group of procedures at once (but multiple @racket[defproc]s 976 grouped by @racket[deftogether] also works for that case). 977 978 When an @racket[id] has multiple calling cases, either they must be 979 defined with a single @racket[defproc*], so that a single definition 980 point exists for the @racket[id], or else all but one definition 981 should use @racket[#:link-target? #f]. 982 983 Examples: 984 @codeblock[#:keep-lang-line? #f]|{ 985 #lang scribble/manual 986 @defproc*[([(make-pb&j) sandwich?] 987 [(make-pb&j [jelly jelly?]) sandwich?])]{ 988 Returns a peanut butter and jelly sandwich. If @racket[jelly] 989 is provided, then it is used instead of the standard (grape) 990 jelly. 991 } 992 }| 993 994 @doc-render-examples[ 995 @defproc*[#:link-target? #f 996 ([(make-pb&j) sandwich?] 997 [(make-pb&j [jelly jelly?]) sandwich?])]{ 998 Returns a peanut butter and jelly sandwich. If @racket[jelly] 999 is provided, then it is used instead of the standard (grape) 1000 jelly. 1001 }] 1002 } 1003 1004 1005 @defform/subs[(defform options form-datum 1006 maybe-grammar maybe-contracts 1007 pre-flow ...) 1008 ([options (code:line maybe-kind maybe-link maybe-id maybe-literals)] 1009 [maybe-kind code:blank 1010 (code:line #:kind kind-content-expr)] 1011 [maybe-link code:blank 1012 (code:line #:link-target? link-target?-expr)] 1013 [maybe-id code:blank 1014 (code:line #:id id) 1015 (code:line #:id [id id-expr])] 1016 [maybe-literals code:blank 1017 (code:line #:literals (literal-id ...))] 1018 [maybe-grammar code:blank 1019 (code:line #:grammar ([nonterm-id clause-datum ...+] ...))] 1020 [maybe-contracts code:blank 1021 (code:line #:contracts ([subform-datum contract-expr-datum] 1022 ...))])]{ 1023 1024 Produces a sequence of flow elements (encapsulated in a 1025 @racket[splice]) to document a syntatic form named by @racket[id] (or the 1026 result of @racket[id-expr]) whose syntax is described by 1027 @racket[form-datum]. If no @racket[#:id] is used to specify 1028 @racket[id], then @racket[form-datum] must have the form @racket[(id 1029 . _datum)]. 1030 1031 If @racket[#:kind kind-content-expr] is supplied, it is used in the 1032 same way as for @racket[defproc], but the default kind is 1033 @racket["syntax"]. 1034 1035 If @racket[#:id [id id-expr]] is supplied, then @racket[id] is the 1036 identifier as it appears in the @racket[form-datum] (to be replaced by 1037 a defining instance), and @racket[id-expr] produces the identifier to 1038 be documented. This split between @racket[id] and @racket[id-expr] 1039 roles is useful for functional abstraction of @racket[defform]. 1040 1041 Unless @racket[link-target?-expr] is specified 1042 and produces @racket[#f], 1043 the @racket[id] (or result of @racket[id-expr]) is indexed, and it is 1044 also registered so that @racket[racket]-typeset uses of the identifier 1045 (with the same for-label binding) are hyperlinked to this 1046 documentation. The @racket[defmodule] or @racket[declare-exporting] 1047 requirements, as well as the binding requirements for @racket[id] (or 1048 result of @racket[id-expr]), are the same as for @racket[defproc]. 1049 1050 The @tech{decode}d @racket[pre-flow] documents the form. In this 1051 description, a reference to any identifier in @racket[form-datum] via 1052 @racket[racket], @racket[racketblock], @|etc| is typeset as a sub-form 1053 non-terminal. If @racket[#:literals] clause is provided, however, 1054 instances of the @racket[literal-id]s are typeset normally (i.e., as 1055 determined by the enclosing context). 1056 1057 If a @racket[#:grammar] clause is provided, it includes an auxiliary 1058 grammar of non-terminals shown with the @racket[id] form. Each 1059 @racket[nonterm-id] is specified as being any of the corresponding 1060 @racket[clause-datum]s. 1061 1062 If a @racket[#:contracts] clause is provided, each 1063 @racket[subform-datum] (typically an identifier that serves as a 1064 meta-variable in @racket[form-datum] or @racket[clause-datum]) is 1065 shown as producing a value that must satisfy the contract described by 1066 @racket[contract-expr-datum]. Use @racket[#:contracts] only to 1067 specify constraints on a @emph{value} produced by an expression; for 1068 constraints on the @emph{syntax} of a @racket[subform-datum], use 1069 grammar notation instead, possibly through an auxiliary grammar 1070 specified with @racket[#:grammar]. 1071 1072 The typesetting of @racket[form-datum], @racket[clause-datum], 1073 @racket[subform-datum], and @racket[contract-expr-datum] preserves the 1074 source layout, like @racket[racketblock]. 1075 1076 Examples: 1077 @codeblock[#:keep-lang-line? #f]|{ 1078 #lang scribble/manual 1079 @defform[(sandwich-promise sandwich-expr) 1080 #:contracts ([sandwich-expr sandwich?])]{ 1081 Returns a promise to construct a sandwich. When forced, the promise 1082 will produce the result of @racket[sandwich-expr]. 1083 } 1084 1085 @defform[#:literals (sandwich mixins) 1086 (sandwich-promise* [sandwich sandwich-expr] 1087 [mixins ingredient-expr ...]) 1088 #:contracts ([sandwich-expr sandwich?] 1089 [ingredient-expr ingredient?])]{ 1090 Returns a promise to construct a sandwich. When forced, the promise 1091 will produce the result of @racket[sandwich-expr]. Each result of 1092 the @racket[ingredient-expr]s will be mixed into the resulting 1093 sandwich. 1094 } 1095 1096 @defform[(sandwich-factory maybe-name factory-component ...) 1097 #:grammar 1098 [(maybe-name (code:line) 1099 name) 1100 (factory-component (code:line #:protein protein-expr) 1101 [vegetable vegetable-expr])]]{ 1102 Constructs a sandwich factory. If @racket[maybe-name] is provided, 1103 the factory will be named. Each of the @racket[factory-component] 1104 clauses adds an additional ingredient to the sandwich pipeline. 1105 } 1106 }| 1107 @doc-render-examples[ 1108 @defform[#:link-target? #f 1109 (sandwich-promise sandwich-expr) 1110 #:contracts ([sandwich-expr sandwich?])]{ 1111 Returns a promise to construct a sandwich. When forced, the promise 1112 will produce the result of @racket[sandwich-expr]. 1113 } 1114 1115 @defform[#:link-target? #f 1116 #:literals (sandwich mixins) 1117 (sandwich-promise* [sandwich sandwich-expr] 1118 [mixins ingredient-expr ...]) 1119 #:contracts ([sandwich-expr sandwich?] 1120 [ingredient-expr ingredient?])]{ 1121 Returns a promise to construct a sandwich. When forced, the promise 1122 will produce the result of @racket[sandwich-expr]. Each result of 1123 the @racket[ingredient-expr]s will be mixed into the resulting 1124 sandwich. 1125 } 1126 1127 @defform[#:link-target? #f 1128 (sandwich-factory maybe-name factory-component ...) 1129 #:grammar 1130 [(maybe-name (code:line) 1131 name) 1132 (factory-component (code:line #:protein protein-expr) 1133 [vegetable vegetable-expr])]]{ 1134 Constructs a sandwich factory. If @racket[maybe-name] is provided, 1135 the factory will be named. Each of the @racket[factory-component] 1136 clauses adds an additional ingredient to the sandwich pipeline. 1137 }] 1138 } 1139 1140 @defform[(defform* options [form-datum ...+] 1141 maybe-grammar maybe-contracts 1142 pre-flow ...)]{ 1143 1144 Like @racket[defform], but for multiple forms using the same 1145 @racket[_id]. 1146 1147 Examples: 1148 @codeblock[#:keep-lang-line? #f]|{ 1149 #lang scribble/manual 1150 @defform*[((call-with-current-sandwich expr) 1151 (call-with-current-sandwich expr sandwich-handler-expr))]{ 1152 Runs @racket[expr] and passes it the value of the current 1153 sandwich. If @racket[sandwich-handler-expr] is provided, its result 1154 is invoked when the current sandwich is eaten. 1155 } 1156 }| 1157 @doc-render-examples[ 1158 @defform*[#:link-target? #f 1159 ((call-with-current-sandwich expr) 1160 (call-with-current-sandwich expr sandwich-handler-expr))]{ 1161 Runs @racket[expr] and passes it the value of the current 1162 sandwich. If @racket[sandwich-handler-expr] is provided, its result 1163 is invoked when the current sandwich is eaten. 1164 }] 1165 } 1166 1167 1168 @defform[(defform/none maybe-kind maybe-literal form-datum 1169 maybe-grammar maybe-contracts 1170 pre-flow ...)]{ 1171 1172 Like @racket[defform] with @racket[#:link-target? #f].} 1173 1174 1175 @defform[(defidform maybe-kind maybe-link id pre-flow ...)]{ 1176 1177 Like @racket[defform], but with a plain @racket[id] as the form.} 1178 1179 1180 @defform*[[(defidform/inline id) 1181 (defidform/inline (@#,racket[unsyntax] id-expr))]]{ 1182 1183 Like @racket[defidform], but @racket[id] (or the result of 1184 @racket[id-expr], analogous to @racket[defform]) is typeset as an 1185 inline element. Use this form sparingly, because the typeset form does 1186 not stand out to the reader as a specification of @racket[id].} 1187 1188 @deftogether[( 1189 @defform[(defsubform options form-datum 1190 maybe-grammar maybe-contracts 1191 pre-flow ...)] 1192 @defform[(defsubform* options [form-datum ...+] 1193 maybe-grammar maybe-contracts 1194 pre-flow ...)] 1195 )]{ 1196 1197 Like @racket[defform] and @racket[defform*], but with 1198 indenting on the left for both the specification and the 1199 @racket[pre-flow]s.} 1200 1201 1202 @defform[(specform maybe-literals datum maybe-grammar maybe-contracts 1203 pre-flow ...)]{ 1204 1205 Like @racket[defform] with @racket[#:link-target? #f], but with 1206 indenting on the left for both the specification and the 1207 @racket[pre-flow]s.} 1208 1209 1210 @defform[(specsubform maybe-literals datum maybe-grammar maybe-contracts 1211 pre-flow ...)]{ 1212 1213 Similar to @racket[defform] with @racket[#:link-target? #f], 1214 but without the initial identifier as an implicit literal, 1215 and the table and flow are typeset indented. This form is 1216 intended for use when refining the syntax of a non-terminal used in a 1217 @racket[defform] or other @racket[specsubform]. For example, it is 1218 used in the documentation for @racket[defproc] in the itemization of 1219 possible shapes for @svar[arg-spec]. 1220 1221 The @racket[pre-flow]s list is parsed as a flow that documents the 1222 procedure. In this description, a reference to any identifier in 1223 @racket[datum] is typeset as a sub-form non-terminal.} 1224 1225 1226 @defform[(specspecsubform maybe-literals datum maybe-grammar maybe-contracts 1227 pre-flow ...)]{ 1228 1229 Like @racket[specsubform], but indented an extra level. Since using 1230 @racket[specsubform] within the body of @racket[specsubform] already 1231 nests indentation, @racket[specspecsubform] is for extra indentation 1232 without nesting a description.} 1233 1234 1235 @deftogether[[ 1236 @defform[(defform/subs options form-datum 1237 ([nonterm-id clause-datum ...+] ...) 1238 maybe-contracts 1239 pre-flow ...)] 1240 @defform[(defform*/subs options [form-datum ...+] 1241 ([nonterm-id clause-datum ...+] ...) 1242 maybe-contracts 1243 pre-flow ...)] 1244 @defform[(specform/subs maybe-literals datum 1245 ([nonterm-id clause-datum ...+] ...) 1246 maybe-contracts 1247 pre-flow ...)] 1248 @defform[(specsubform/subs maybe-literals datum 1249 ([nonterm-id clause-datum ...+] ...) 1250 maybe-contracts 1251 pre-flow ...)] 1252 @defform[(specspecsubform/subs maybe-literals datum 1253 ([nonterm-id clause-datum ...+] ...) 1254 maybe-contracts 1255 pre-flow ...)]]]{ 1256 1257 Like @racket[defform], @racket[defform*], @racket[specform], 1258 @racket[specsubform], and @racket[specspecsubform], respectively, but 1259 the auxiliary grammar is mandatory and the @racket[#:grammar] keyword 1260 is omitted. 1261 1262 Examples: 1263 @codeblock[#:keep-lang-line? #f]|{ 1264 #lang scribble/manual 1265 @defform/subs[(sandwich-factory maybe-name factory-component ...) 1266 [(maybe-name (code:line) 1267 name) 1268 (factory-component (code:line #:protein protein-expr) 1269 [vegetable vegetable-expr])]]{ 1270 Constructs a sandwich factory. If @racket[maybe-name] is provided, 1271 the factory will be named. Each of the @racket[factory-component] 1272 clauses adds an additional ingredient to the sandwich pipeline. 1273 } 1274 }| 1275 @doc-render-examples[ 1276 @defform/subs[#:link-target? #f 1277 (sandwich-factory maybe-name factory-component ...) 1278 [(maybe-name (code:line) 1279 name) 1280 (factory-component (code:line #:protein protein-expr) 1281 [vegetable vegetable-expr])]]{ 1282 Constructs a sandwich factory. If @racket[maybe-name] is provided, 1283 the factory will be named. Each of the @racket[factory-component] 1284 clauses adds an additional ingredient to the sandwich pipeline. 1285 }] 1286 } 1287 1288 1289 @defform[(defparam maybe-link id arg-id 1290 contract-expr-datum 1291 maybe-value 1292 pre-flow ...)]{ 1293 1294 Like @racket[defproc], but for a parameter. The 1295 @racket[contract-expr-datum] serves as both the result contract on the 1296 parameter and the contract on values supplied for the parameter. The 1297 @racket[arg-id] refers to the parameter argument in the latter case. 1298 1299 Examples: 1300 @codeblock[#:keep-lang-line? #f]|{ 1301 #lang scribble/manual 1302 @defparam[current-sandwich sandwich sandwich? 1303 #:value empty-sandwich]{ 1304 A parameter that defines the current sandwich for operations that 1305 involve eating a sandwich. Default value is the empty sandwich. 1306 } 1307 }| 1308 @doc-render-examples[ 1309 @defparam[#:link-target? #f 1310 current-sandwich sandwich sandwich? #:value empty-sandwich]{ 1311 A parameter that defines the current sandwich for operations that 1312 involve eating a sandwich. Default value is the empty sandwich. 1313 }] 1314 } 1315 1316 1317 @defform[(defparam* maybe-link id arg-id 1318 in-contract-expr-datum out-contract-expr-datum 1319 maybe-value 1320 pre-flow ...)]{ 1321 1322 Like @racket[defparam], but with separate contracts for when the parameter is being 1323 set versus when it is being retrieved (for the case that a parameter guard 1324 coerces values matching a more flexible contract to a more restrictive one; 1325 @racket[current-directory] is an example).} 1326 1327 1328 @defform[(defboolparam maybe-link id arg-id 1329 maybe-value 1330 pre-flow ...)]{ 1331 1332 Like @racket[defparam], but the contract on a parameter argument is 1333 @racket[any/c], and the contract on the parameter result is 1334 @racket[boolean?].} 1335 1336 1337 @defform/subs[(defthing options id contract-expr-datum maybe-value 1338 pre-flow ...) 1339 ([options (code:line maybe-kind maybe-link maybe-id)] 1340 [maybe-kind code:blank 1341 (code:line #:kind kind-content-expr)] 1342 [maybe-link code:blank 1343 (code:line #:link-target? link-target?-expr)] 1344 [maybe-id code:blank 1345 (code:line #:id id-expr)] 1346 [maybe-value code:blank 1347 (code:line #:value value-expr-datum)])]{ 1348 1349 Like @racket[defproc], but for a non-procedure binding. 1350 1351 If @racket[#:kind kind-content-expr] is supplied, 1352 it is used in the same way as for 1353 @racket[defproc], but the default kind is @racket["value"]. 1354 1355 If @racket[#:id id-expr] is supplied, then the result of 1356 @racket[id-expr] is used in place of @racket[id]. 1357 1358 If @racket[#:value value-expr-datum] is given, @racket[value-expr-datum] 1359 is typeset using @racket[racketblock0] and included in the documentation. 1360 Wide values are put on a separate line. 1361 1362 Examples: 1363 @codeblock[#:keep-lang-line? #f]|{ 1364 #lang scribble/manual 1365 @defthing[moldy-sandwich sandwich?]{ 1366 Don't eat this. Provided for backwards compatibility. 1367 } 1368 1369 @defthing[empty-sandwich sandwich? #:value (make-sandwich empty)]{ 1370 The empty sandwich. 1371 } 1372 }| 1373 @doc-render-examples[ 1374 @defthing[#:link-target? #f 1375 moldy-sandwich sandwich?]{ 1376 Don't eat this. Provided for backwards compatibility. 1377 } 1378 @defthing[#:link-target? #f 1379 empty-sandwich sandwich? #:value (make-sandwich empty)]{ 1380 The empty sandwich. 1381 }] 1382 } 1383 1384 1385 @deftogether[( 1386 @defform[ (defstruct* maybe-link struct-name ([field-name contract-expr-datum] ...) 1387 maybe-mutable maybe-non-opaque maybe-constructor 1388 pre-flow ...)] 1389 @defform/subs[ (defstruct maybe-link struct-name ([field-name contract-expr-datum] ...) 1390 maybe-mutable maybe-non-opaque maybe-constructor 1391 pre-flow ...) 1392 ([maybe-link code:blank 1393 (code:line #:link-target? link-target?-expr)] 1394 [struct-name id 1395 (id super-id)] 1396 [maybe-mutable code:blank 1397 #:mutable] 1398 [maybe-non-opaque code:blank 1399 #:prefab 1400 #:transparent 1401 (code:line #:inspector #f)] 1402 [maybe-constructor code:blank 1403 (code:line #:constructor-name constructor-id) 1404 (code:line #:extra-constructor-name constructor-id) 1405 (code:line #:omit-constructor)])] 1406 )]{ 1407 1408 Similar to @racket[defform] or @racket[defproc], but for a structure 1409 definition. The @racket[defstruct*] form corresponds to @racket[struct], 1410 while @racket[defstruct] corresponds to @racket[define-struct]. 1411 1412 Examples: 1413 1414 An example using @racket[defstruct]: 1415 @codeblock[#:keep-lang-line? #f]|{ 1416 #lang scribble/manual 1417 @defstruct[sandwich ([protein ingredient?] [sauce ingredient?])]{ 1418 A structure type for sandwiches. Sandwiches are a pan-human foodstuff 1419 composed of a partially-enclosing bread material and various 1420 ingredients. 1421 } 1422 }| 1423 @doc-render-examples[ 1424 @defstruct[#:link-target? #f 1425 sandwich ([protein ingredient?] [sauce ingredient?])]{ 1426 A structure type for sandwiches. Sandwiches are a pan-human foodstuff 1427 composed of a partially-enclosing bread material and various 1428 ingredients. 1429 }] 1430 1431 Additionally, an example using @racket[defstruct*]: 1432 @codeblock[#:keep-lang-line? #f]|{ 1433 #lang scribble/manual 1434 @defstruct*[burrito ([salsa ingredient?] [tortilla ingredient?])]{ 1435 A structure type for burritos. Burritos are a pan-human foodstuff 1436 composed of a @emph{fully}-encolosed bread material and various 1437 ingredients. 1438 } 1439 }| 1440 } 1441 @doc-render-examples[ 1442 @defstruct*[#:link-target? #f 1443 burrito ([salsa ingredient?] [tortilla ingredient?])]{ 1444 A structure type for burritos. Burritos are a pan-human foodstuff 1445 composed of a @emph{fully}-encolosed bread material and various 1446 ingredients. 1447 }] 1448 1449 1450 @defform[(deftogether [def-expr ...] pre-flow ...)]{ 1451 1452 Combines the definitions created by the @racket[def-expr]s into a 1453 single definition box. Each @racket[def-expr] should produce a 1454 definition point via @racket[defproc], @racket[defform], etc. Each 1455 @racket[def-expr] should have an empty @racket[pre-flow]; the 1456 @tech{decode}d @racket[pre-flow] sequence for the @racket[deftogether] 1457 form documents the collected bindings. 1458 1459 Examples: 1460 @codeblock[#:keep-lang-line? #f]|{ 1461 #lang scribble/manual 1462 @deftogether[(@defthing[test-sandwich-1 sandwich?] 1463 @defthing[test-sandwich-2 sandwich?])]{ 1464 Two high-quality sandwiches. These are provided for convenience 1465 in writing test cases 1466 } 1467 }| 1468 @doc-render-examples[ 1469 @deftogether[(@defthing[#:link-target? #f test-sandwich-1 sandwich?] 1470 @defthing[#:link-target? #f test-sandwich-2 sandwich?])]{ 1471 Two high-quality sandwiches. These are provided for convenience 1472 in writing test cases 1473 } 1474 ] 1475 } 1476 1477 1478 @defform/subs[(racketgrammar maybe-literals id clause-datum ...+) 1479 ([maybe-literals code:blank 1480 (code:line #:literals (literal-id ...))])]{ 1481 1482 Creates a table to define the grammar of @racket[id]. Each identifier 1483 mentioned in a @racket[clause-datum] is typeset as a non-terminal, 1484 except for the identifiers listed as @racket[literal-id]s, which are 1485 typeset as with @racket[racket].} 1486 1487 1488 @defform[(racketgrammar* maybe-literals [id clause-datum ...+] ...)]{ 1489 1490 Like @racket[racketgrammar], but for typesetting multiple productions 1491 at once, aligned around the @litchar{=} and @litchar{|}.} 1492 1493 @defproc[(defidentifier [id identifier?] 1494 [#:form? form? boolean? #f] 1495 [#:index? index? boolean? #t] 1496 [#:show-libs? show-libs? boolean? #t]) 1497 element?]{ 1498 1499 Typesets @racket[id] as a Racket identifier, and also establishes the 1500 identifier as the definition of a binding in the same way as 1501 @racket[defproc], @racket[defform], etc. As always, the library that 1502 provides the identifier must be declared via @racket[defmodule] or 1503 @racket[declare-exporting] for an enclosing section. 1504 1505 If @racket[form?] is a true value, then the identifier is documented 1506 as a syntactic form, so that uses of the identifier (normally 1507 including @racket[id] itself) are typeset as a syntactic form. 1508 1509 If @racket[index?] is a true value, then the identifier is registered 1510 in the index. 1511 1512 If @racket[show-libs?] is a true value, then the identifier's defining 1513 module may be exposed in the typeset form (e.g., when viewing HTML and 1514 the mouse hovers over the identifier).} 1515 1516 @deftogether[( 1517 @defform[(schemegrammar maybe-literals id clause-datum ...+)] 1518 @defform[(schemegrammar* maybe-literals [id clause-datum ...+] ...)] 1519 )]{ 1520 1521 Compatibility aliases for @racket[racketgrammar] and @racket[racketgrammar*].} 1522 1523 @defparam[current-display-width w exact-nonnegative-integer?]{ 1524 1525 Specifies the target maximum width in characters for the output of 1526 @racket[defproc] and @racket[defstruct].} 1527 1528 1529 @; ------------------------------------------------------------------------ 1530 @section[#:tag "doc-classes"]{Documenting Classes and Interfaces} 1531 1532 @defform/subs[(defclass maybe-link id super (intf-id ...) pre-flow ...) 1533 ([maybe-link code:blank 1534 (code:line #:link-target? link-target?-expr)] 1535 [super super-id 1536 (mixin-id super)])]{ 1537 1538 Creates documentation for a class @racket[id] that is a subclass of 1539 @racket[super] and implements each interface @racket[intf-id]. Each 1540 identifier in @racket[super] (except @racket[object%]) and 1541 @racket[intf-id] must be documented somewhere via @racket[defclass] or 1542 @racket[definterface]. 1543 1544 The decoding of the @racket[pre-flow] sequence should start with 1545 general documentation about the class, followed by constructor 1546 definition (see @racket[defconstructor]), and then field and method 1547 definitions (see @racket[defmethod]). In rendered form, the 1548 constructor and method specification are indented to visually group 1549 them under the class definition.} 1550 1551 @defform[(defclass/title maybe-link id super (intf-id ...) pre-flow ...)]{ 1552 1553 Like @racket[defclass], also includes a @racket[title] declaration 1554 with the style @racket['hidden]. In addition, the constructor and 1555 methods are not left-indented. 1556 1557 This form is normally used to create a section to be rendered on its 1558 own HTML. The @racket['hidden] style is used because the definition 1559 box serves as a title.} 1560 1561 @defform[(definterface id (intf-id ...) pre-flow ...)]{ 1562 1563 Like @racket[defclass], but for an interfaces. Naturally, 1564 @racket[pre-flow] should not generate a constructor declaration.} 1565 1566 @defform[(definterface/title id (intf-id ...) pre-flow ...)]{ 1567 1568 Like @racket[definterface], but for single-page rendering as in 1569 @racket[defclass/title].} 1570 1571 @defform[(defmixin id (domain-id ...) (range-id ...) pre-flow ...)]{ 1572 1573 Like @racket[defclass], but for a mixin. Any number of 1574 @racket[domain-id] classes and interfaces are specified for the 1575 mixin's input requires, and any number of result classes and (more 1576 likely) interfaces are specified for the @racket[range-id]. The 1577 @racket[domain-id]s supply inherited methods.} 1578 1579 @defform[(defmixin/title id (domain-id ...) (range-id ...) pre-flow ...)]{ 1580 1581 Like @racket[defmixin], but for single-page rendering as in 1582 @racket[defclass/title].} 1583 1584 @defform/subs[(defconstructor (arg-spec ...) pre-flow ...) 1585 ([arg-spec (arg-id contract-expr-datum) 1586 (arg-id contract-expr-datum default-expr)])]{ 1587 1588 Like @racket[defproc], but for a constructor declaration in the body 1589 of @racket[defclass], so no return contract is specified. Also, the 1590 @racket[new]-style keyword for each @racket[arg-spec] is implicit from 1591 the @racket[arg-id].} 1592 1593 @defform[(defconstructor/make (arg-spec ...) pre-flow ...)]{ 1594 1595 Like @racket[defconstructor], but specifying by-position 1596 initialization arguments (for use with @racket[make-object]) instead 1597 of by-name arguments (for use with @racket[new]).} 1598 1599 @defform[(defconstructor*/make [(arg-spec ...) ...] pre-flow ...)]{ 1600 1601 Like @racket[defconstructor/make], but with multiple constructor 1602 patterns analogous @racket[defproc*].} 1603 1604 @defform[(defconstructor/auto-super [(arg-spec ...) ...] pre-flow ...)]{ 1605 1606 Like @racket[defconstructor], but the constructor is 1607 annotated to indicate that additional initialization arguments are 1608 accepted and propagated to the superclass.} 1609 1610 @defform/subs[#:literals (override override-final public-final 1611 augment augment-final pubment extend extend-final) 1612 (defmethod maybe-mode maybe-link (id arg-spec ...) 1613 result-contract-expr-datum 1614 pre-flow ...) 1615 ([maybe-link code:blank 1616 (code:line #:link-target? link-target?-expr)] 1617 [maybe-mode code:blank 1618 (code:line #:mode public) 1619 (code:line #:mode public-final) 1620 (code:line #:mode override) 1621 (code:line #:mode override-final) 1622 (code:line #:mode augment) 1623 (code:line #:mode augment-final) 1624 (code:line #:mode extend) 1625 (code:line #:mode extend-final) 1626 (code:line #:mode pubment)])]{ 1627 1628 Like @racket[defproc], but for a method within a @racket[defclass] or 1629 @racket[definterface] body. 1630 1631 The @racket[maybe-mode] specifies whether the method overrides a 1632 method from a superclass, and so on. (For these purposes, use 1633 @racket[#:mode override] when refining a method of an implemented 1634 interface.) The @racket[extend] mode is like @racket[override], but 1635 the description of the method should describe only extensions to the 1636 superclass implementation. When @racket[maybe-mode] is not supplied, 1637 it defaults to @racket[public]. 1638 1639 @history[#:changed "1.35" @elem{Added a check against invalid @racket[maybe-mode].}]} 1640 1641 @defform[(defmethod* maybe-mode maybe-link 1642 ([(id arg-spec ...) 1643 result-contract-expr-datum] ...) 1644 pre-flow ...)]{ 1645 1646 Like @racket[defproc*], but for a method within a @racket[defclass] or 1647 @racket[definterface] body. The @racket[maybe-mode] specification is as in 1648 @racket[defmethod].} 1649 1650 1651 @defform[(method class/intf-id method-id)]{ 1652 1653 Creates a hyperlink to the method named by @racket[method-id] in the 1654 class or interface named by @racket[class/intf-id]. The hyperlink 1655 names the method, only; see also @racket[xmethod]. 1656 1657 For-label binding information is used with @racket[class/intf-id], but 1658 not @racket[method-id].} 1659 1660 @defform[(xmethod class/intf-id method-id)]{ 1661 1662 Like @racket[method], but the hyperlink shows both the method name and 1663 the containing class/interface.} 1664 1665 @defform[(this-obj)]{ 1666 1667 Within a @racket[defmethod] or similar form, typesets as a 1668 meta-variable that stands for the target of the method call. Use 1669 @racket[(this-obj)] to be more precise than prose such as ``this 1670 method's object.''} 1671 1672 @; ------------------------------------------------------------------------ 1673 @section[#:tag "doc-signatures"]{Documenting Signatures} 1674 1675 @defform[(defsignature id (super-id ...) pre-flow ...)]{ 1676 1677 Defines a signature @racket[id] that extends the @racket[super-id] 1678 signatures. Any elements defined in @tech{decode}d 1679 @racket[pre-flow]s---including forms, procedures, structure types, 1680 classes, interfaces, and mixins---are defined as members of the 1681 signature instead of direct bindings. These definitions can be 1682 referenced through @racket[sigelem] instead of @racket[racket]. 1683 1684 The @tech{decode}d @racket[pre-flow]s inset under the signature 1685 declaration in the typeset output, so no new sections, @|etc| can be 1686 started.} 1687 1688 @defform[(defsignature/splice id (super-id ...) pre-flow ...)]{ 1689 1690 Like @racket[defsignature], but the @tech{decode}d @racket[pre-flow]s 1691 are not typeset under the signature declaration, and new sections, 1692 @|etc| can be started in the @racket[pre-flow]s.} 1693 1694 @defproc[(signature-desc [pre-flow pre-flow?] ...) any/c]{ 1695 1696 Produces an opaque value that @racket[defsignature] recognizes to 1697 outdent in the typeset form. This is useful for text describing the 1698 signature as a whole to appear right after the signature declaration.} 1699 1700 @defform[(sigelem sig-id id)]{ 1701 1702 Typesets the identifier @racket[id] with a hyperlink to its definition 1703 as a member of the signature named by @racket[sig-id].} 1704 1705 @; ------------------------------------------------------------------------ 1706 @section[#:tag "doc-strings"]{Various String Forms} 1707 1708 @defproc[(aux-elem [pre-content pre-content?] ...) element?]{ 1709 Like @racket[elem], but adds an @racket['aux] @tech{style property}.} 1710 1711 @defproc[(defterm [pre-content pre-content?] ...) element?]{Typesets the 1712 @tech{decode}d @racket[pre-content] as a defined term (e.g., in 1713 italic). Consider using @racket[deftech] instead, though, so that uses 1714 of @racket[tech] can hyper-link to the definition.} 1715 1716 @defproc[(onscreen [pre-content pre-content?] ...) element?]{ Typesets the 1717 @tech{decode}d @racket[pre-content] as a string that appears in a GUI, 1718 such as the name of a button.} 1719 1720 @defproc[(menuitem [menu-name string?] [item-name string?]) element?]{ 1721 Typesets the given combination of a GUI's menu and item name.} 1722 1723 @defproc[(filepath [pre-content pre-content?] ...) element?]{Typesets the 1724 @tech{decode}d @racket[pre-content] as a file name (e.g., in 1725 typewriter font and in quotes).} 1726 1727 @defproc[(exec [content content?] ...) element?]{Typesets the 1728 @racket[content] as a command line (e.g., in typewriter font).} 1729 1730 @defproc[(envvar [pre-content pre-content?] ...) element?]{Typesets the given 1731 @tech{decode}d @racket[pre-content] as an environment variable (e.g., 1732 in typewriter font).} 1733 1734 @defproc[(Flag [pre-content pre-content?] ...) element?]{Typesets the given 1735 @tech{decode}d @racket[pre-content] as a flag (e.g., in typewriter 1736 font with a leading @litchar{-}).} 1737 1738 @defproc[(DFlag [pre-content pre-content?] ...) element?]{Typesets the given 1739 @tech{decode}d @racket[pre-content] a long flag (e.g., in typewriter 1740 font with two leading @litchar{-}s).} 1741 1742 @defproc[(PFlag [pre-content pre-content?] ...) element?]{Typesets the given 1743 @tech{decode}d @racket[pre-content] as a @litchar{+} flag (e.g., in typewriter 1744 font with a leading @litchar{+}).} 1745 1746 @defproc[(DPFlag [pre-content pre-content?] ...) element?]{Typesets the given 1747 @tech{decode}d @racket[pre-content] a long @litchar{+} flag (e.g., in 1748 typewriter font with two leading @litchar{+}s).} 1749 1750 @; ------------------------------------------------------------------------ 1751 @section[#:tag "section-links"]{Links} 1752 1753 See also @secref["base-links"]. 1754 1755 @defform*[[(racketlink id #:style style-expr pre-content ...) 1756 (racketlink id pre-content ...)] 1757 #:contracts ([id identifier?] 1758 [pre-content pre-content?])]{ 1759 1760 An element where the @tech{decode}d @racket[pre-content] is hyperlinked to the definition 1761 of @racket[id].} 1762 1763 @defform[(schemelink id pre-content ...)]{ 1764 1765 Compatibility alias for @racket[racketlink].} 1766 1767 @defproc[(link [url string?] [pre-content any/c] ... 1768 [#:underline? underline? any/c #t] 1769 [#:style style (or/c style? string? symbol? #f) (if underline? #f "plainlink")]) 1770 element?]{ 1771 1772 Alias of @racket[hyperlink] for backward compatibility.} 1773 1774 @defproc[(other-manual [module-path module-path?] 1775 [#:underline? underline? any/c #t]) 1776 element?]{ 1777 1778 Alias of @racket[other-doc] for backward compatibility.} 1779 1780 @defproc[(deftech [pre-content pre-content?] ... 1781 [#:key key (or/c string? #f) #f] 1782 [#:normalize? normalize? any/c #t] 1783 [#:style? style? any/c #t]) element?]{ 1784 1785 Produces an element for the @tech{decode}d @racket[pre-content], and 1786 also defines a term that can be referenced elsewhere using 1787 @racket[tech]. 1788 1789 When @racket[key] is @racket[#f], the @racket[content->string] result 1790 of the @tech{decode}d @racket[pre-content] is used as a key for 1791 references. If @racket[normalize?] is true, then the key string is 1792 normalized as follows: 1793 1794 @itemize[ 1795 1796 @item{The string is case-folded.} 1797 1798 @item{A trailing ``ies'' is replaced by ``y''.} 1799 1800 @item{A trailing ``s'' is removed.} 1801 1802 @item{Consecutive hyphens and whitespaces are all replaced by a 1803 single space.} 1804 1805 ] 1806 1807 These normalization steps help support natural-language references 1808 that differ slightly from a defined form. For example, a definition of 1809 ``bananas'' can be referenced with a use of ``banana''. 1810 1811 If @racket[style?] is true, then @racket[defterm] is used on 1812 @racket[pre-content].} 1813 1814 @defproc[(tech [pre-content pre-content?] ... 1815 [#:key key (or/c string? #f) #f] 1816 [#:normalize? normalize? any/c #t] 1817 [#:doc module-path (or/c module-path? #f) #f] 1818 [#:tag-prefixes prefixes (or/c (listof string?) #f) #f]) 1819 element?]{ 1820 1821 Produces an element for the @tech{decode}d @racket[pre-content], and 1822 hyperlinks it to the definition of the key as established by 1823 @racket[deftech]. If @racket[key] is false, the decoded content is 1824 converted to a string (using @racket[content->string]) to use as a 1825 key; in either case, if @racket[normalize?] is true, the key is normalized in the same way as for 1826 @racket[deftech]. The @racket[#:doc] and @racket[#:tag-prefixes] 1827 arguments support cross-document and section-specific references, like 1828 in @racket[secref]. 1829 For example: 1830 @racketblock[@tech[#:doc '(lib "scribblings/reference/reference.scrbl")]{blame object}] 1831 1832 creates a link to @tech[#:doc '(lib "scribblings/reference/reference.scrbl")]{blame object} in 1833 @other-doc['(lib "scribblings/reference/reference.scrbl")]. 1834 1835 With the default style files, the hyperlink created by @racket[tech] 1836 is somewhat quieter than most hyperlinks: the underline in HTML output 1837 is gray, instead of blue, and the term and underline turn blue only 1838 when the mouse is moved over the term. 1839 1840 In some cases, combining both natural-language uses of a term and 1841 proper linking can require some creativity, even with the 1842 normalization performed on the term. For example, if ``bind'' is 1843 defined, but a sentence uses the term ``binding,'' the latter can be 1844 linked to the former using @racketfont["@tech{bind}ing"].} 1845 1846 @defproc[(techlink [pre-content pre-content?] ... 1847 [#:key key (or/c string? #f) #f] 1848 [#:normalize? normalize? any/c #t] 1849 [#:doc module-path (or/c module-path? #f) #f] 1850 [#:tag-prefixes prefixes (or/c (listof string?) #f) #f]) 1851 element?]{ 1852 1853 Like @racket[tech], but the link is not quiet. For example, in HTML 1854 output, a hyperlink underline appears even when the mouse is not over 1855 the link.} 1856 1857 @; ------------------------------------------------------------------------ 1858 @section[#:tag "manual-indexing"]{Indexing} 1859 1860 See also @secref["base-indexing"] for @racketmodname[scribble/base]. 1861 1862 @defform[(indexed-racket datum ...)]{ 1863 1864 A combination of @racket[racket] and @racket[as-index], with the 1865 following special cases when a single @racket[datum] is provided: 1866 1867 @itemize[ 1868 1869 @item{If @racket[datum] is a @racket[quote] form, then the quote is 1870 removed from the key (so that it's sorted using its unquoted 1871 form).} 1872 1873 @item{If @racket[datum] is a string, then quotes are removed from the 1874 key (so that it's sorted using the string content).} 1875 1876 ]} 1877 1878 @defform[(indexed-scheme datum ...)]{ 1879 1880 Compatibility alias for @racket[indexed-racket].} 1881 1882 @defproc[(idefterm [pre-content pre-content?] ...) element?]{Combines 1883 @racket[as-index] and @racket[defterm]. The content normally should be 1884 plural, rather than singular. Consider using @racket[deftech], 1885 instead, which always indexes.} 1886 1887 @defproc[(pidefterm [pre-content pre-content?] ...) element?]{Like 1888 @racket[idefterm], but plural: adds an ``s'' on the end of the content 1889 for the index entry. Consider using @racket[deftech], instead.} 1890 1891 @defproc[(indexed-file [pre-content pre-content?] ...) element?]{A 1892 combination of @racket[file] and @racket[as-index], but where the sort 1893 key for the index iterm does not include quotes.} 1894 1895 @defproc[(indexed-envvar [pre-content pre-content?] ...) element?]{A 1896 combination of @racket[envvar] and @racket[as-index].} 1897 1898 @; ------------------------------------------------------------------------ 1899 @section{Bibliography} 1900 1901 @margin-note{See also @racketmodname[scriblib/autobib].} 1902 1903 @defproc[(cite [key string?] ...+) element?]{ 1904 1905 Links to a bibliography entry, using the @racket[key]s both to indicate the 1906 bibliography entry and, in square brackets, as the link text.} 1907 1908 @defproc[(bibliography [#:tag tag string? "doc-bibliography"] 1909 [entry bib-entry?] ...) 1910 part?]{ 1911 1912 Creates a bibliography part containing the given entries, each of 1913 which is created with @racket[bib-entry]. The entries are typeset in 1914 order as given.} 1915 1916 @defproc[(bib-entry [#:key key string?] 1917 [#:title title (or/c #f pre-content?)] 1918 [#:is-book? is-book? boolean? #f] 1919 [#:author author (or/c #f pre-content?) #f] 1920 [#:location location (or/c #f pre-content?) #f] 1921 [#:date date (or/c #f pre-content?) #f] 1922 [#:url url (or/c #f pre-content?) #f] 1923 [#:note note (or/c #f pre-content?) #f]) 1924 bib-entry?]{ 1925 1926 Creates a bibliography entry. The @racket[key] is used to refer to the 1927 entry via @racket[cite]. The other arguments are used as elements in 1928 the entry: 1929 1930 @itemize[ 1931 1932 @item{@racket[title] is the title of the cited work. It will be 1933 surrounded by quotes in typeset form if @racket[is-book?] is 1934 @racket[#f], otherwise it is typeset via @racket[italic].} 1935 1936 @item{@racket[author] lists the authors. Use names in their usual 1937 order (as opposed to ``last, first''), and separate multiple 1938 names with commas using ``and'' before the last name (where 1939 there are multiple names). The @racket[author] is typeset in 1940 the bibliography as given, or it is omitted if given as 1941 @racket[#f].} 1942 1943 @item{@racket[location] names the publication venue, such as a 1944 conference name or a journal with volume, number, and 1945 pages. The @racket[location] is typeset in the bibliography as 1946 given, or it is omitted if given as @racket[#f].} 1947 1948 @item{@racket[date] is a date, usually just a year (as a string). It 1949 is typeset in the bibliography as given, or it is omitted if 1950 given as @racket[#f].} 1951 1952 @item{@racket[url] is an optional URL. It is typeset in the 1953 bibliography using @racket[tt] and hyperlinked, or it is 1954 omitted if given as @racket[#f].} 1955 1956 @item{@racket[note] is an optional comment about the work. It is typeset 1957 in the bibliography as given, and appears directly after the date 1958 (or URL, if given) with no space or punctuation in between.} 1959 ] 1960 1961 @history[#:changed "1.29" @elem{Added the @racket[#:note] option.}]} 1962 1963 1964 @defproc[(bib-entry? [v any/c]) boolean?]{ 1965 1966 Returns @racket[#t] if @racket[v] is a bibliography entry created by 1967 @racket[bib-entry], @racket[#f] otherwise.} 1968 1969 1970 @; ------------------------------------------------------------------------ 1971 @section{Version History} 1972 1973 @defform[(history clause ...) 1974 #:grammar ([clause (code:line #:added version-expr) 1975 (code:line #:changed version-expr content-expr)]) 1976 #:contracts ([version-expr valid-version?] 1977 [content-expr content?])]{ 1978 1979 Generates a @tech{block} for version-history notes. The version 1980 refers to a package as determined by a @racket[defmodule] or 1981 @racket[declare-exporting] declaration within an enclosing section. 1982 1983 Normally, @racket[history] should be used at the end of a 1984 @racket[defform], @racket[defproc], @|etc|, entry, although it may 1985 also appear in a section that introduces a module (that has been added 1986 to a package). In the case of a @racket[changed] entry, the content 1987 produced by @racket[content-expr] should normally start with a capital 1988 letter and end with a period, but it can be a sentence fragment such 1989 as ``Added a @racket[#:changed] form.'' 1990 1991 Examples: 1992 @codeblock[#:keep-lang-line? #f]|{ 1993 #lang scribble/manual 1994 @defthing[tasty-burrito burrito?]{ 1995 Compatible with the API of a sandwich, but not legally a 1996 sandwich in Massachusetts. 1997 1998 @history[#:added "1.0" 1999 #:changed "1.1" "Refactored tortilla." 2000 #:changed "1.2" @elem{Now includes @emph{guacamole}.}] 2001 } 2002 }| 2003 @doc-render-examples[ 2004 @defthing[tasty-burrito burrito?]{ 2005 Compatible with the API of a sandwich, but not legally a 2006 sandwich in Massachusetts. 2007 2008 @history[#:added "1.0" 2009 #:changed "1.1" "Refactored tortilla." 2010 #:changed "1.2" @elem{Now includes @emph{guacamole}.}] 2011 }] 2012 2013 @history[#:added "1.1"]} 2014 2015 @; ------------------------------------------------------------------------ 2016 @section{Miscellaneous} 2017 2018 @defproc[(t [pre-content pre-content?] ...) paragraph?]{Wraps the 2019 @tech{decode}d @racket[pre-content] as a paragraph.} 2020 2021 @defthing[etc element?]{Like @racket["etc."], but with an 2022 abbreviation-ending period for use in the middle of a sentence.} 2023 2024 @defthing[PLaneT element?]{@racket["PLaneT"] (to help make sure you get 2025 the letters in the right case).} 2026 2027 @defthing[manual-doc-style style?]{ 2028 2029 A style to be used for a document's main @racket[part] to get the 2030 style configuration of @racket[@#,hash-lang[] @#,racketmodname[scribble/manual]]. 2031 See @secref["manual-render-style"].} 2032 2033 @defproc[(hash-lang) element?]{Returns an element for @hash-lang[] 2034 that is hyperlinked to an explanation.} 2035 2036 @defthing[void-const element?]{Returns an element for @|void-const|.} 2037 2038 @defthing[undefined-const element?]{Returns an element for @|undefined-const|.} 2039 2040 @defproc[(commandline [content content?] ...) paragraph?]{Produces 2041 an inset command-line example (e.g., in typewriter font).} 2042 2043 @defproc[(inset-flow [pre-flow pre-flow?] ...) nested-flow?]{ 2044 2045 Creates a @racket[nested-flow] with indenting on the left and right. 2046 2047 Using @racket[nested] with the @racket['inset] style is a prefered 2048 alternative.} 2049 2050 @defproc[(centerline [pre-flow pre-flow?] ...) nested-flow?]{ 2051 2052 An alias for @racket[centered] for backward compatibility.} 2053 2054 @defproc[(math [pre-content any/c] ...) element?]{The @tech{decode}d 2055 @racket[pre-content] is further transformed: 2056 2057 @itemize[ 2058 2059 @item{Any immediate @racket['rsquo] is converted to @racket['prime].} 2060 2061 @item{Parentheses and sequences of decimal digits in immediate 2062 strings are left as-is, but any other immediate string is 2063 italicized.} 2064 2065 @item{When @litchar{_} appears before a non-empty sequence of numbers 2066 and letters, the sequence is typeset as a subscript.} 2067 2068 @item{When @litchar{^} appears before a non-empty sequence of numbers 2069 and letters, the sequence is typeset as a superscript.} 2070 2071 ]} 2072 2073 @defproc[(filebox [filename (or/c string? element?)] [pre-flow pre-flow?] ...) 2074 block?]{ 2075 2076 Typesets the @racket[pre-flow]s as the content of 2077 @racket[filename]. For example, the content may be inset on the page 2078 with @racket[filename] above it. If @racket[filename] is a string, it 2079 is passed to @racket[filepath] to obtain an @racket[element].} 2080 2081 @defproc[(deprecated [#:what what content? "library"] 2082 [replacement content?] 2083 [additional-notes content?] ...) 2084 block?]{ 2085 Produces an inset warning for deprecated libraries, functions, @|etc| (as 2086 described by @racket[what]), where @racket[replacement] describes a 2087 suitable replacement. The @racket[additional-notes] are included after the 2088 initial deprecation message.} 2089 2090 @defproc[(image/plain [filename-relative-to-source string?] 2091 [pre-element any/c] ...) 2092 element?]{ 2093 2094 An alias for @racket[image] for backward compatibility.} 2095 2096 @; ------------------------------------------------------------------------ 2097 @section[#:tag "index-entries"]{Index-Entry Descriptions} 2098 2099 @defmodule[scribble/manual-struct]{The 2100 @racketmodname[scribble/manual-struct] library provides types used to 2101 describe index entries created by @racketmodname[scribble/manual] 2102 functions. These structure types are provided separate from 2103 @racketmodname[scribble/manual] so that 2104 @racketmodname[scribble/manual] need not be loaded when deserializing 2105 cross-reference information that was generated by a previously 2106 rendered document.} 2107 2108 @defstruct[module-path-index-desc ()]{ 2109 2110 Indicates that the index entry corresponds to a module definition via 2111 @racket[defmodule] and company.} 2112 2113 @deftogether[( 2114 @defstruct[(language-index-desc module-path-index-desc) ()]{} 2115 @defstruct[(reader-index-desc module-path-index-desc) ()]{} 2116 )]{ 2117 Indicates that the index entry corresponds to a module definition via 2118 @racket[defmodule] with the @racket[#:lang] or @racket[#:reader] option. 2119 For example, a module definition via @racket[defmodulelang] has a 2120 @racket[language-index-desc] index entry and a module definition via 2121 @racket[defmodulereader] has a @racket[reader-index-desc] index entry.} 2122 2123 @defstruct[exported-index-desc ([name symbol?] 2124 [from-libs (listof module-path?)])]{ 2125 2126 Indicates that the index entry corresponds to the definition of an 2127 exported binding. The @racket[name] field and @racket[from-libs] list 2128 correspond to the documented name of the binding and the primary 2129 modules that export the documented name (but this list is not 2130 exhaustive, because new modules can re-export the binding).} 2131 2132 @defstruct[(form-index-desc exported-index-desc) ()]{ 2133 2134 Indicates that the index entry corresponds to the definition of a 2135 syntactic form via @racket[defform] and company.} 2136 2137 @defstruct[(procedure-index-desc exported-index-desc) ()]{ 2138 2139 Indicates that the index entry corresponds to the definition of a 2140 procedure binding via @racket[defproc] and company.} 2141 2142 @defstruct[(thing-index-desc exported-index-desc) ()]{ 2143 2144 Indicates that the index entry corresponds to the definition of a 2145 binding via @racket[defthing] and company.} 2146 2147 @defstruct[(struct-index-desc exported-index-desc) ()]{ 2148 2149 Indicates that the index entry corresponds to the definition of a 2150 structure type via @racket[defstruct] and company.} 2151 2152 @defstruct[(class-index-desc exported-index-desc) ()]{ 2153 2154 Indicates that the index entry corresponds to the definition of a 2155 class via @racket[defclass] and company.} 2156 2157 @defstruct[(interface-index-desc exported-index-desc) ()]{ 2158 2159 Indicates that the index entry corresponds to the definition of an 2160 interface via @racket[definterface] and company.} 2161 2162 @defstruct[(mixin-index-desc exported-index-desc) ()]{ 2163 2164 Indicates that the index entry corresponds to the definition of a 2165 mixin via @racket[defmixin] and company.} 2166 2167 @defstruct[(method-index-desc exported-index-desc) ([method-name symbol?] 2168 [class-tag tag?])]{ 2169 2170 Indicates that the index entry corresponds to the definition of an 2171 method via @racket[defmethod] and company. The @racket[_name] field 2172 from @racket[exported-index-desc] names the class or interface that 2173 contains the method. The @racket[method-name] field names the method. 2174 The @racket[class-tag] field provides a pointer to the start of the 2175 documentation for the method's class or interface.} 2176 2177 @defstruct[(constructor-index-desc exported-index-desc) ([class-tag tag?])]{ 2178 2179 Indicates that the index entry corresponds to a constructor 2180 via @racket[defconstructor] and company. The @racket[_name] field 2181 from @racket[exported-index-desc] names the class or interface that 2182 contains the method. 2183 The @racket[class-tag] field provides a pointer to the start of the 2184 documentation for the method's class or interface.} 2185 2186 @;---------------------------------------- 2187 2188 @section[#:tag "manual-render-style"]{Manual Rendering Style} 2189 2190 Using @racket[@#,hash-lang[] @#,racketmodname[scribble/manual]] for the 2191 main @racket[part] of a document associates @tech{style properties} on 2192 the @racket[doc] export to select the Racket manual style for 2193 rendering. 2194 2195 A @racket[html-defaults] @tech{style property} is added to 2196 @racket[doc], unless @racket[doc]'s style already has a 2197 @racket[html-defaults] @tech{style property} (e.g., supplied to 2198 @racket[title]). Similarly, a @racket[latex-default] @tech{style 2199 property} is added if one is not already present. Finally, an 2200 @racket[css-style-addition] property is always added. 2201 2202 For HTML rendering: 2203 2204 @itemlist[ 2205 2206 @item{The document's @tech{prefix file} is set to 2207 @filepath{scribble-prefix.html}, as usual, in @racket[html-defaults].} 2208 2209 @item{The document's @tech{style file} is set to 2210 @filepath{manual-style.css} from the @filepath{scribble} 2211 collection in @racket[html-defaults].} 2212 2213 @item{The file @filepath{manual-fonts.css} from the 2214 @filepath{scribble} collection is designated as an additional 2215 accompanying file in @racket[html-defaults].} 2216 2217 @item{The file @filepath{manual-racket.css} from the 2218 @filepath{scribble} collection is added as a 2219 @racket[css-style-addition].} 2220 2221 ] 2222 2223 To obtain this configuration without using @racket[@#,hash-lang[] 2224 @#,racketmodname[scribble/manual]], use @racket[manual-doc-style].