more doc fixes

svn: r7881
This commit is contained in:
Matthew Flatt 2007-12-01 02:47:17 +00:00
parent 58684c1b0b
commit c9545a836b
6 changed files with 64 additions and 40 deletions

View File

@ -45,14 +45,18 @@
(define-struct (sized-element element) (length)) (define-struct (sized-element element) (length))
(define-struct spaces (pre cnt post)) (define-struct (spaces element) (cnt))
(define (literalize-spaces i) (define (literalize-spaces i)
(let ([m (regexp-match-positions #rx" +" i)]) (let ([m (regexp-match-positions #rx" +" i)])
(if m (if m
(make-spaces (literalize-spaces (substring i 0 (caar m))) (let ([cnt (- (cdar m) (caar m))])
(- (cdar m) (caar m)) (make-spaces #f
(literalize-spaces (substring i (cdar m)))) (list
(literalize-spaces (substring i 0 (caar m)))
(make-element 'hspace (list (make-string cnt #\space)))
(literalize-spaces (substring i (cdar m))))
cnt))
i))) i)))
(define (typeset-atom c out color? quote-depth) (define (typeset-atom c out color? quote-depth)
@ -150,17 +154,17 @@
[(delayed-element? v) [(delayed-element? v)
(element-width v)] (element-width v)]
[(spaces? v) [(spaces? v)
(+ (sz-loop (spaces-pre v)) (+ (sz-loop (car (element-content v)))
(spaces-cnt v) (spaces-cnt v)
(sz-loop (spaces-post v)))] (sz-loop (caddr (element-content v))))]
[else 1])))] [else 1])))]
[(v cls len) [(v cls len)
(unless (equal? v "") (unless (equal? v "")
(cond (cond
[(spaces? v) [(spaces? v)
(out (spaces-pre v) cls 0) (out (car (element-content v)) cls 0)
(out (make-element 'hspace (list (make-string (spaces-cnt v) #\space))) #f 0) (out (cadr (element-content v)) #f 0)
(out (spaces-post v) cls len)] (out (caddr (element-content v)) cls len)]
[(equal? v "\n") [(equal? v "\n")
(if multi-line? (if multi-line?
(begin (begin

View File

@ -66,7 +66,7 @@
(syntax-case stx () (syntax-case stx ()
[(_ (id ([field ct] ...)) ...) [(_ (id ([field ct] ...)) ...)
#`(begin #`(begin
(define-serializable-struct id (field ...) #:mutable) ... (define-serializable-struct id (field ...)) ...
(provide/contract (provide/contract
#,@(let ([ids (syntax->list #'(id ...))] #,@(let ([ids (syntax->list #'(id ...))]
[fields+cts (syntax->list #'(([field ct] ...) ...))]) [fields+cts (syntax->list #'(([field ct] ...) ...))])

View File

@ -131,12 +131,11 @@ structure type are kept private to a module, then no other module can
rely on the representation of the type's instances. rely on the representation of the type's instances.
To make a structure type @defterm{transparent}, use the To make a structure type @defterm{transparent}, use the
@scheme[#:inspector] keyword with the value @scheme[#f] after the @scheme[#:transparent] keyword after the field-name sequence:
field-name sequence:
@def+int[ @def+int[
(define-struct posn (x y) (define-struct posn (x y)
#:inspector #f) #:transparent)
(make-posn 1 2) (make-posn 1 2)
] ]
@ -144,8 +143,7 @@ An instance of a transparent structure type prints like a vector, and
it shows the content of the structure's fields. A transparent it shows the content of the structure's fields. A transparent
structure type also allows reflective operations, such as structure type also allows reflective operations, such as
@scheme[struct?] and @scheme[struct-info], to be used on its instances @scheme[struct?] and @scheme[struct-info], to be used on its instances
(see @secref["reflection"]). Different values for @scheme[#:inspector] (see @secref["reflection"]).
support more controlled access to reflective operations.
Structure types are opaque by default, because opaque structure Structure types are opaque by default, because opaque structure
instances provide more encapsulation guarantees. That is, a library instances provide more encapsulation guarantees. That is, a library
@ -192,10 +190,13 @@ A @scheme[_struct-option] always starts with a keyword:
(set-person-age! friend 6) (set-person-age! friend 6)
(set-person-name! friend "Mary")]} (set-person-name! friend "Mary")]}
@specspecsubform[(code:line #:inspector inspector-expr)]{ @specspecsubform[(code:line #:transparent)]{
Controls reflective access to structure instances, as discussed Controls reflective access to structure instances, as discussed
in the previous section (@secref["trans-struct"]). in the previous section (@secref["trans-struct"]).}
}
@specspecsubform[(code:line #:inspector inspector-expr)]{
Generalizes @scheme[#:transparent] to support more controlled access
to reflective operations.}
@specspecsubform[(code:line #:auto-value auto-expr)]{ @specspecsubform[(code:line #:auto-value auto-expr)]{
@ -206,7 +207,7 @@ A @scheme[_struct-option] always starts with a keyword:
@defexamples[ @defexamples[
(define-struct posn (x y [z #:auto]) (define-struct posn (x y [z #:auto])
#:inspector #f #:transparent
#:auto-value 0) #:auto-value 0)
(make-posn 1 2) (make-posn 1 2)
]} ]}
@ -224,7 +225,7 @@ A @scheme[_struct-option] always starts with a keyword:
@defexamples[ @defexamples[
(define-struct thing (name) (define-struct thing (name)
#:inspector #f #:transparent
#:guard (lambda (name type-name) #:guard (lambda (name type-name)
(cond (cond
[(string? name) name] [(string? name) name]
@ -242,7 +243,7 @@ A @scheme[_struct-option] always starts with a keyword:
@defexamples[ @defexamples[
(define-struct (person thing) (age) (define-struct (person thing) (age)
#:inspector #f #:transparent
#:guard (lambda (name age type-name) #:guard (lambda (name age type-name)
(if (negative? age) (if (negative? age)
(error "bad age" age) (error "bad age" age)
@ -282,7 +283,7 @@ A @scheme[_struct-option] always starts with a keyword:
(define (make-raven-constructor super-type) (define (make-raven-constructor super-type)
(define-struct raven () (define-struct raven ()
#:super super-type #:super super-type
#:inspector #f #:transparent
#:property prop:procedure (lambda (self) #:property prop:procedure (lambda (self)
'nevermore)) 'nevermore))
make-raven) make-raven)
@ -307,7 +308,7 @@ times.
@defexamples[ @defexamples[
(define (add-bigger-fish lst) (define (add-bigger-fish lst)
(define-struct fish (size) #:inspector #f) (code:comment #,(t "new every time")) (define-struct fish (size) #:transparent) (code:comment #,(t "new every time"))
(cond (cond
[(null? lst) (list (make-fish 1))] [(null? lst) (list (make-fish 1))]
[else (cons (make-fish (* 2 (fish-size (car lst)))) [else (cons (make-fish (* 2 (fish-size (car lst))))
@ -317,7 +318,7 @@ times.
(add-bigger-fish (add-bigger-fish null)) (add-bigger-fish (add-bigger-fish null))
] ]
@defs+int[ @defs+int[
[(define-struct fish (size) #:inspector #f) [(define-struct fish (size) #:transparent)
(define (add-bigger-fish lst) (define (add-bigger-fish lst)
(cond (cond
[(null? lst) (list (make-fish 1))] [(null? lst) (list (make-fish 1))]

View File

@ -16,6 +16,8 @@ A @tech{module path} that is a quoted identifier refers to a non-file
@scheme[module] declaration using the identifier. This form of module @scheme[module] declaration using the identifier. This form of module
reference makes the most sense in a @tech{REPL}. reference makes the most sense in a @tech{REPL}.
@interaction-eval[(compile-enforce-module-constants #f)]
@examples[ @examples[
(module m scheme (module m scheme
(provide color) (provide color)
@ -26,6 +28,8 @@ reference makes the most sense in a @tech{REPL}.
(require 'n) (require 'n)
]} ]}
@interaction-eval[(compile-enforce-module-constants #t)]
@; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@specsubform[id]{ @specsubform[id]{

View File

@ -114,6 +114,13 @@ banner text for an embedding program, such as MrEd). The banner string
ends with a newline.} ends with a newline.}
@defparam[current-command-line-arguments argv (vectorof (and/c string? immutable?))]{
A parameter that is initialized with command-line arguments when
Scheme starts (not including any command-line arguments that were
treated as flags for the system).}
@defproc[(vector-set-performance-stats! [results (and/c vector? @defproc[(vector-set-performance-stats! [results (and/c vector?
(not/c immutable?))] (not/c immutable?))]
[thd (or/c thread? false/c) #f]) [thd (or/c thread? false/c) #f])

View File

@ -204,20 +204,28 @@
(loop base))))))) (loop base)))))))
only-dirs))) only-dirs)))
(define (ensure-doc-prefix! src-file v) (define (ensure-doc-prefix v src-file)
(let ([p (format "~a" (let ([p (format "~a"
(path->main-collects-relative src-file))]) (path->main-collects-relative src-file))])
(if (part-tag-prefix v) (when (part-tag-prefix v)
(unless (equal? p (unless (equal? p
(part-tag-prefix v)) (part-tag-prefix v))
(error 'setup (error 'setup
"bad tag prefix: ~e for: ~a expected: ~e" "bad tag prefix: ~e for: ~a expected: ~e"
(part-tag-prefix v) (part-tag-prefix v)
src-file src-file
p)) p)))
(set-part-tag-prefix! v p)) (let ([tag-prefix p]
(unless (member '(part "top") (part-tags v)) [tags (if (member '(part "top") (part-tags v))
(set-part-tags! v (cons '(part "top") (part-tags v)))))) (part-tags v)
(cons '(part "top") (part-tags v)))])
(make-part tag-prefix
tags
(part-title-content v)
(part-style v)
(part-to-collect v)
(part-flow v)
(part-parts v)))))
(define ((get-doc-info only-dirs latex-dest) doc) (define ((get-doc-info only-dirs latex-dest) doc)
(let ([info-out-file (build-path (or latex-dest (doc-dest-dir doc)) "out.sxref")] (let ([info-out-file (build-path (or latex-dest (doc-dest-dir doc)) "out.sxref")]
@ -267,9 +275,9 @@
#f))) #f)))
;; Run the doc once: ;; Run the doc once:
(parameterize ([current-directory (doc-src-dir doc)]) (parameterize ([current-directory (doc-src-dir doc)])
(let ([v (dynamic-require-doc (doc-src-file doc))] (let ([v (ensure-doc-prefix (dynamic-require-doc (doc-src-file doc))
(doc-src-file doc))]
[dest-dir (pick-dest latex-dest doc)]) [dest-dir (pick-dest latex-dest doc)])
(ensure-doc-prefix! (doc-src-file doc) v)
(let* ([ci (send renderer collect (list v) (list dest-dir))]) (let* ([ci (send renderer collect (list v) (list dest-dir))])
(let ([ri (send renderer resolve (list v) (list dest-dir) ci)] (let ([ri (send renderer resolve (list v) (list dest-dir) ci)]
[out-v (and info-out-time [out-v (and info-out-time
@ -314,9 +322,9 @@
(doc-src-file doc)) (doc-src-file doc))
(set-info-rendered?! info #t) (set-info-rendered?! info #t)
(parameterize ([current-directory (doc-src-dir doc)]) (parameterize ([current-directory (doc-src-dir doc)])
(let ([v (dynamic-require-doc (doc-src-file doc))] (let ([v (ensure-doc-prefix (dynamic-require-doc (doc-src-file doc))
(doc-src-file doc))]
[dest-dir (pick-dest latex-dest doc)]) [dest-dir (pick-dest latex-dest doc)])
(ensure-doc-prefix! (doc-src-file doc) v)
(let* ([ci (send renderer collect (list v) (list dest-dir))]) (let* ([ci (send renderer collect (list v) (list dest-dir))])
(for-each (lambda (i) (for-each (lambda (i)
(send renderer deserialize-info (info-sci i) ci)) (send renderer deserialize-info (info-sci i) ci))