speed up doc build a little; fix bugs related to getting continuation marks from a thread and using the errortrace profiler
svn: r12237
This commit is contained in:
parent
a6743b3089
commit
37aae202c5
|
@ -96,15 +96,15 @@ you also need to ensure that @scheme[instrumenting-enabled] is on.}
|
|||
@defboolparam[profiling-record-enabled on?]{
|
||||
|
||||
Enables/disables the recording of profiling info for the instrumented code.
|
||||
The default is @scheme[#t].}
|
||||
The default is @scheme[#t].
|
||||
|
||||
Profiling information is accumulated in a hash table. If a procedure
|
||||
is redefined, new profiling information is accumulated for the new
|
||||
version of the procedure, but the old information is also preserved.
|
||||
|
||||
Depending of the source program, profiling usually induces a factor of
|
||||
2 to 4 slowdown in addition to any slowdown from the exception
|
||||
information instrumentation.
|
||||
2 to 4 slowdown, in addition to any slowdown from the
|
||||
exception-information instrumentation.}
|
||||
|
||||
@defproc[(output-profile-results [paths? any/c] [sort-time? any/c]) void?]{
|
||||
|
||||
|
|
|
@ -208,7 +208,7 @@
|
|||
(let loop ([bodys bodys])
|
||||
(if (null? (cdr bodys))
|
||||
(list (cons (car bodys) prof-expr))
|
||||
(cons (cons (car bodys) #'(void))
|
||||
(cons (cons (car bodys) #'(#%plain-app void))
|
||||
(loop (cdr bodys))))))
|
||||
;; Map 1-to-1:
|
||||
(map cons bodys bodyl)))))
|
||||
|
|
|
@ -109,10 +109,9 @@
|
|||
(or location source)))))
|
||||
|
||||
;; unpack-blame : any/c -> any/c
|
||||
;; Constructs an S-expression for use in the blame error messages
|
||||
;; when blaming the module where stx's occurs, where the context
|
||||
;; is represented by a variable reference. Other representations of
|
||||
;; blame are returned as-is.
|
||||
;; Constructs an S-expression for use in the blame error messages.
|
||||
;; A variable reference represents a module or top-level context.
|
||||
;; Other representations of blame are returned as-is.
|
||||
(define (unpack-blame blame)
|
||||
(if (variable-reference? blame)
|
||||
(let ([rp (variable-reference->resolved-module-path blame)])
|
||||
|
|
|
@ -383,6 +383,7 @@
|
|||
|
||||
(define/public (render-element i part ri)
|
||||
(cond
|
||||
[(string? i) (render-other i part ri)] ; short-cut for common case
|
||||
[(and (link-element? i)
|
||||
(null? (element-content i)))
|
||||
(let ([v (resolve-get part ri (link-element-tag i))])
|
||||
|
|
|
@ -127,11 +127,11 @@
|
|||
v)))
|
||||
v)))
|
||||
|
||||
(define (module-path-index->taglet mod)
|
||||
(define (do-module-path-index->taglet mod)
|
||||
;; Derive the name from the module path:
|
||||
(let ([p (collapse-module-path-index
|
||||
mod
|
||||
(build-path (current-directory) "dummy"))])
|
||||
(lambda () (build-path (current-directory) "dummy")))])
|
||||
(if (path? p)
|
||||
;; If we got a path back anyway, then it's best to use the resolved
|
||||
;; name; if the current directory has changed since we
|
||||
|
@ -160,6 +160,13 @@
|
|||
p)])
|
||||
(intern-taglet p)))))
|
||||
|
||||
(define collapsed (make-weak-hasheq))
|
||||
(define (module-path-index->taglet mod)
|
||||
(or (hash-ref collapsed mod #f)
|
||||
(let ([v (do-module-path-index->taglet mod)])
|
||||
(hash-set! collapsed mod v)
|
||||
v)))
|
||||
|
||||
(define (module-path-prefix->string p)
|
||||
(format "~a" (module-path-index->taglet (module-path-index-join p #f))))
|
||||
|
||||
|
|
|
@ -91,18 +91,16 @@
|
|||
(define (anchor-name v)
|
||||
(define (encode-byte b)
|
||||
(string-append (if (< b 16) "~0" "~") (number->string b 16)))
|
||||
(define (encode-str str)
|
||||
(if (regexp-match? #px"[^[:ascii:]]" str)
|
||||
(string-append* (map encode-byte (bytes->list (string->bytes/utf-8 str))))
|
||||
(encode-byte (char->integer (string-ref str 0)))))
|
||||
(define (encode-bytes str)
|
||||
(string->bytes/utf-8 (encode-byte (bytes-ref str 0))))
|
||||
(if (literal-anchor? v)
|
||||
(literal-anchor-string v)
|
||||
(let* ([v (format "~a" v)]
|
||||
[v (regexp-replace* #rx"[A-Z.]" v ".&")]
|
||||
[v (regexp-replace* #rx" " v "._")]
|
||||
[v (regexp-replace* #rx"\"" v ".'")]
|
||||
[v (regexp-replace* #rx"[^-a-zA-Z0-9_!+*'()/.,]" v encode-str)])
|
||||
v)))
|
||||
(let* ([v (string->bytes/utf-8 (format "~a" v))]
|
||||
[v (regexp-replace* #rx#"[A-Z.]" v #".&")]
|
||||
[v (regexp-replace* #rx#" " v #"._")]
|
||||
[v (regexp-replace* #rx#"\"" v #".'")]
|
||||
[v (regexp-replace* #rx#"[^-a-zA-Z0-9_!+*'()/.,]" v encode-bytes)])
|
||||
(bytes->string/utf-8 v))))
|
||||
|
||||
(define-serializable-struct literal-anchor (string))
|
||||
|
||||
|
@ -826,6 +824,7 @@
|
|||
|
||||
(define/override (render-element e part ri)
|
||||
(cond
|
||||
[(string? e) (super render-element e part ri)] ; short-cut for common case
|
||||
[(hover-element? e)
|
||||
`((span ([title ,(hover-element-text e)])
|
||||
,@(render-plain-element e part ri)))]
|
||||
|
@ -1270,9 +1269,16 @@
|
|||
(loop (cdr path) (cdr root))))))
|
||||
roots))))
|
||||
|
||||
(define exploded (make-weak-hash))
|
||||
(define (explode/cache p)
|
||||
(or (hash-ref exploded p #f)
|
||||
(let ([v (explode p)])
|
||||
(hash-set! exploded p v)
|
||||
v)))
|
||||
|
||||
(define (from-root p d)
|
||||
(define e-p (explode (path->complete-path p (current-directory))))
|
||||
(define e-d (and d (explode (path->complete-path d (current-directory)))))
|
||||
(define e-p (explode/cache (path->complete-path p (current-directory))))
|
||||
(define e-d (and d (explode/cache (path->complete-path d (current-directory)))))
|
||||
(define p-in? (in-plt? e-p))
|
||||
(define d-in? (and d (in-plt? e-d)))
|
||||
;; use an absolute link if the link is from outside the plt tree
|
||||
|
@ -1287,12 +1293,13 @@
|
|||
(let loop ([e-d e-d] [e-p e-p])
|
||||
(cond
|
||||
[(null? e-d)
|
||||
(let loop ([e-p e-p])
|
||||
(cond [(null? e-p) "/"]
|
||||
[(null? (cdr e-p)) (car e-p)]
|
||||
[(eq? 'same (car e-p)) (loop (cdr e-p))]
|
||||
[(eq? 'up (car e-p)) (string-append "../" (loop (cdr e-p)))]
|
||||
[else (string-append (car e-p) "/" (loop (cdr e-p)))]))]
|
||||
(string-append*
|
||||
(let loop ([e-p e-p])
|
||||
(cond [(null? e-p) '("/")]
|
||||
[(null? (cdr e-p)) (list (car e-p))]
|
||||
[(eq? 'same (car e-p)) (loop (cdr e-p))]
|
||||
[(eq? 'up (car e-p)) (cons "../" (loop (cdr e-p)))]
|
||||
[else (cons (car e-p) (cons "/" (loop (cdr e-p))))])))]
|
||||
[(equal? (car e-d) (car e-p)) (loop (cdr e-d) (cdr e-p))]
|
||||
[(eq? 'same (car e-d)) (loop (cdr e-d) e-p)]
|
||||
[(eq? 'same (car e-p)) (loop e-d (cdr e-p))]
|
||||
|
|
|
@ -295,8 +295,9 @@
|
|||
(*sig-elem (sig-id sig) (extract-id prototype))
|
||||
(to-element (make-just-context (extract-id prototype)
|
||||
stx-id)))))]))
|
||||
(define p-depth (prototype-depth prototype))
|
||||
(define flat-size (+ (prototype-size args + + #f)
|
||||
(prototype-depth prototype)
|
||||
p-depth
|
||||
(element-width tagged)))
|
||||
(define short? (or (flat-size . < . 40) ((length args) . < . 2)))
|
||||
(define res
|
||||
|
@ -319,7 +320,7 @@
|
|||
(loop (cdr res))))))))))
|
||||
res)))
|
||||
(define tagged+arg-width (+ (prototype-size args max max #t)
|
||||
(prototype-depth prototype)
|
||||
p-depth
|
||||
(element-width tagged)))
|
||||
(define result-next-line?
|
||||
((+ (if short? flat-size tagged+arg-width) (block-width res))
|
||||
|
@ -339,10 +340,10 @@
|
|||
(to-flow
|
||||
(make-element
|
||||
#f
|
||||
`(,(make-openers (add1 (prototype-depth prototype)))
|
||||
`(,(make-openers (add1 p-depth))
|
||||
,tagged
|
||||
,@(if (null? args)
|
||||
(list (make-closers (prototype-depth prototype)))
|
||||
(list (make-closers p-depth))
|
||||
(append-map (lambda (arg)
|
||||
(list spacer ((arg->elem #t) arg)))
|
||||
args))
|
||||
|
@ -363,7 +364,7 @@
|
|||
(make-element
|
||||
#f
|
||||
(list
|
||||
(make-openers (add1 (prototype-depth prototype)))
|
||||
(make-openers (add1 p-depth))
|
||||
tagged)))
|
||||
(if one-ok?
|
||||
(list*
|
||||
|
|
|
@ -68,6 +68,7 @@ streams like this:
|
|||
null?
|
||||
(cons/c number? stream/c))))
|
||||
]
|
||||
@close-eval[e]
|
||||
|
||||
Unfortunately, this does not work because the value of
|
||||
@scheme[stream/c] is needed before it is defined. Put another way, all
|
||||
|
|
|
@ -22,7 +22,7 @@ A byte string can be used as a single-valued sequence (see
|
|||
@secref["sequences"]). The bytes of the string serve as elements
|
||||
of the sequence. See also @scheme[in-bytes].
|
||||
|
||||
See also: @scheme[immutable].
|
||||
See also: @scheme[immutable?].
|
||||
|
||||
@; ----------------------------------------
|
||||
@section{Byte String Constructors, Selectors, and Mutators}
|
||||
|
@ -30,21 +30,21 @@ See also: @scheme[immutable].
|
|||
@defproc[(bytes? [v any/c]) boolean?]{ Returns @scheme[#t] if @scheme[v]
|
||||
is a byte string, @scheme[#f] otherwise.
|
||||
|
||||
@examples[(bytes? #"Apple") (bytes? "Apple")]}
|
||||
@mz-examples[(bytes? #"Apple") (bytes? "Apple")]}
|
||||
|
||||
|
||||
@defproc[(make-bytes [k exact-nonnegative-integer?] [b byte? 0])
|
||||
bytes?]{ Returns a new mutable byte string of length @scheme[k] where each
|
||||
position in the byte string is initialized with the byte @scheme[b].
|
||||
|
||||
@examples[(make-bytes 5 65)]}
|
||||
@mz-examples[(make-bytes 5 65)]}
|
||||
|
||||
|
||||
@defproc[(bytes [b byte?] ...) bytes?]{ Returns a new mutable byte
|
||||
string whose length is the number of provided @scheme[b]s, and whose
|
||||
positions are initialized with the given @scheme[b]s.
|
||||
|
||||
@examples[(bytes 65 112 112 108 101)]}
|
||||
@mz-examples[(bytes 65 112 112 108 101)]}
|
||||
|
||||
|
||||
@defproc[(bytes->immutable-bytes [bstr bytes?])
|
||||
|
@ -59,13 +59,13 @@ positions are initialized with the given @scheme[b]s.
|
|||
a byte (i.e., an exact integer between @scheme[0] and @scheme[255]
|
||||
inclusive), @scheme[#f] otherwise.
|
||||
|
||||
@examples[(byte? 65) (byte? 0) (byte? 256) (byte? -1)]}
|
||||
@mz-examples[(byte? 65) (byte? 0) (byte? 256) (byte? -1)]}
|
||||
|
||||
|
||||
@defproc[(bytes-length [bstr bytes?]) exact-nonnegative-integer?]{
|
||||
Returns the length of @scheme[bstr].
|
||||
|
||||
@examples[(bytes-length #"Apple")]}
|
||||
@mz-examples[(bytes-length #"Apple")]}
|
||||
|
||||
|
||||
@defproc[(bytes-ref [bstr bytes?] [k exact-nonnegative-integer?])
|
||||
|
@ -74,7 +74,7 @@ positions are initialized with the given @scheme[b]s.
|
|||
position @scheme[k] must be less than the length of the bytes,
|
||||
otherwise the @exnraise[exn:fail:contract].
|
||||
|
||||
@examples[(bytes-ref #"Apple" 0)]}
|
||||
@mz-examples[(bytes-ref #"Apple" 0)]}
|
||||
|
||||
|
||||
@defproc[(bytes-set! [bstr (and/c bytes? (not/c immutable?))] [k
|
||||
|
@ -84,9 +84,9 @@ positions are initialized with the given @scheme[b]s.
|
|||
@scheme[k] must be less than the length of the bytes, otherwise the
|
||||
@exnraise[exn:fail:contract].
|
||||
|
||||
@examples[(define s (bytes 65 112 112 108 101))
|
||||
(bytes-set! s 4 121)
|
||||
s]}
|
||||
@mz-examples[(define s (bytes 65 112 112 108 101))
|
||||
(bytes-set! s 4 121)
|
||||
s]}
|
||||
|
||||
|
||||
@defproc[(subbytes [bstr bytes?] [start exact-nonnegative-integer?]
|
||||
|
@ -98,8 +98,8 @@ positions are initialized with the given @scheme[b]s.
|
|||
@scheme[bstr], and @scheme[end] must be greater than or equal to @scheme[bstr],
|
||||
otherwise the @exnraise[exn:fail:contract].
|
||||
|
||||
@examples[(subbytes #"Apple" 1 3)
|
||||
(subbytes #"Apple" 1)]}
|
||||
@mz-examples[(subbytes #"Apple" 1 3)
|
||||
(subbytes #"Apple" 1)]}
|
||||
|
||||
|
||||
@defproc[(bytes-copy [bstr bytes?]) bytes?]{ Returns
|
||||
|
@ -124,18 +124,18 @@ positions are initialized with the given @scheme[b]s.
|
|||
account the sizes of the bytes strings and the source and destination
|
||||
regions), the @exnraise[exn:fail:contract].
|
||||
|
||||
@examples[(define s (bytes 65 112 112 108 101))
|
||||
(bytes-copy! s 4 #"y")
|
||||
(bytes-copy! s 0 s 3 4)
|
||||
s]}
|
||||
@mz-examples[(define s (bytes 65 112 112 108 101))
|
||||
(bytes-copy! s 4 #"y")
|
||||
(bytes-copy! s 0 s 3 4)
|
||||
s]}
|
||||
|
||||
@defproc[(bytes-fill! [dest (and/c bytes? (not/c immutable?))] [char
|
||||
char?]) void?]{ Changes @scheme[dest] so that every position in the
|
||||
bytes is filled with @scheme[char].
|
||||
|
||||
@examples[(define s (bytes 65 112 112 108 101))
|
||||
(bytes-fill! s 113)
|
||||
s]}
|
||||
@mz-examples[(define s (bytes 65 112 112 108 101))
|
||||
(bytes-fill! s 113)
|
||||
s]}
|
||||
|
||||
|
||||
@defproc[(bytes-append [bstr bytes?] ...) bytes?]{
|
||||
|
@ -146,7 +146,7 @@ that contains the concatenated bytes of the given @scheme[bstr]s. If
|
|||
no @scheme[bstr]s are provided, the result is a zero-length byte
|
||||
string.
|
||||
|
||||
@examples[(bytes-append #"Apple" #"Banana")]}
|
||||
@mz-examples[(bytes-append #"Apple" #"Banana")]}
|
||||
|
||||
|
||||
@defproc[(bytes->list [bstr bytes?]) (listof byte?)]{ Returns a new
|
||||
|
@ -155,7 +155,7 @@ string.
|
|||
sequence of bytes of @scheme[bstr] are in the same sequence in the
|
||||
result list.
|
||||
|
||||
@examples[(bytes->list #"Apple")]}
|
||||
@mz-examples[(bytes->list #"Apple")]}
|
||||
|
||||
|
||||
@defproc[(list->bytes [lst (listof byte?)]) bytes?]{ Returns a new
|
||||
|
@ -164,7 +164,7 @@ string.
|
|||
the sequence of bytes in @scheme[lst] is in the same sequence in
|
||||
the result bytes.
|
||||
|
||||
@examples[(list->bytes (list 65 112 112 108 101))]}
|
||||
@mz-examples[(list->bytes (list 65 112 112 108 101))]}
|
||||
|
||||
|
||||
@; ----------------------------------------
|
||||
|
@ -173,8 +173,8 @@ string.
|
|||
@defproc[(bytes=? [bstr1 bytes?] [bstr2 bytes?] ...+) boolean?]{ Returns
|
||||
@scheme[#t] if all of the arguments are @scheme[eqv?].}
|
||||
|
||||
@examples[(bytes=? #"Apple" #"apple")
|
||||
(bytes=? #"a" #"as" #"a")]
|
||||
@mz-examples[(bytes=? #"Apple" #"apple")
|
||||
(bytes=? #"a" #"as" #"a")]
|
||||
|
||||
@(define (bytes-sort direction)
|
||||
@elem{Like @scheme[bytes<?], but checks whether the arguments are @|direction|.})
|
||||
|
@ -184,16 +184,16 @@ string.
|
|||
increasing, where individual bytes are ordered by @scheme[<],
|
||||
@scheme[#f] otherwise.
|
||||
|
||||
@examples[(bytes<? #"Apple" #"apple")
|
||||
(bytes<? #"apple" #"Apple")
|
||||
(bytes<? #"a" #"b" #"c")]}
|
||||
@mz-examples[(bytes<? #"Apple" #"apple")
|
||||
(bytes<? #"apple" #"Apple")
|
||||
(bytes<? #"a" #"b" #"c")]}
|
||||
|
||||
@defproc[(bytes>? [bstr1 bytes?] [bstr2 bytes?] ...+) boolean?]{
|
||||
@bytes-sort["decreasing"]
|
||||
|
||||
@examples[(bytes>? #"Apple" #"apple")
|
||||
(bytes>? #"apple" #"Apple")
|
||||
(bytes>? #"c" #"b" #"a")]}
|
||||
@mz-examples[(bytes>? #"Apple" #"apple")
|
||||
(bytes>? #"apple" #"Apple")
|
||||
(bytes>? #"c" #"b" #"a")]}
|
||||
|
||||
@; ----------------------------------------
|
||||
@section{Bytes to/from Characters, Decoding and Encoding}
|
||||
|
|
|
@ -29,7 +29,7 @@ otherwise.}
|
|||
|
||||
Returns a character's code-point number.
|
||||
|
||||
@examples[(char->integer #\A)]}
|
||||
@mz-examples[(char->integer #\A)]}
|
||||
|
||||
|
||||
@defproc[(integer->char [k (and/c exact-integer?
|
||||
|
@ -41,7 +41,7 @@ Return the character whose code-point number is @scheme[k]. For
|
|||
@scheme[k] less than @scheme[256], the result is the same object for
|
||||
the same @scheme[k].
|
||||
|
||||
@examples[(integer->char 65)]}
|
||||
@mz-examples[(integer->char 65)]}
|
||||
|
||||
|
||||
@defproc[(char-utf-8-length [char char?]) (integer-in 1 6)]{
|
||||
|
@ -57,7 +57,7 @@ Produces the same result as @scheme[(bytes-length (string->bytes/utf-8
|
|||
|
||||
Returns @scheme[#t] if all of the arguments are @scheme[eqv?].
|
||||
|
||||
@examples[(char=? #\a #\a)
|
||||
@mz-examples[(char=? #\a #\a)
|
||||
(char=? #\a #\A #\a)]}
|
||||
|
||||
@(define (char-sort direction folded?)
|
||||
|
@ -71,68 +71,68 @@ Returns @scheme[#t] if the arguments are sorted increasing, where
|
|||
two characters are ordered by their scalar values, @scheme[#f]
|
||||
otherwise.
|
||||
|
||||
@examples[(char<? #\A #\a)
|
||||
(char<? #\a #\A)
|
||||
(char<? #\a #\b #\c)]}
|
||||
@mz-examples[(char<? #\A #\a)
|
||||
(char<? #\a #\A)
|
||||
(char<? #\a #\b #\c)]}
|
||||
|
||||
@defproc[(char<=? [char1 char?] [char2 char?] ...+) boolean?]{
|
||||
@char-sort["nondecreasing" #f]
|
||||
|
||||
@examples[(char<=? #\A #\a)
|
||||
(char<=? #\a #\A)
|
||||
(char<=? #\a #\b #\b)]}
|
||||
@mz-examples[(char<=? #\A #\a)
|
||||
(char<=? #\a #\A)
|
||||
(char<=? #\a #\b #\b)]}
|
||||
|
||||
@defproc[(char>? [char1 char?] [char2 char?] ...+) boolean?]{
|
||||
@char-sort["decreasing" #f]
|
||||
|
||||
@examples[(char>? #\A #\a)
|
||||
(char>? #\a #\A)
|
||||
(char>? #\c #\b #\a)]}
|
||||
@mz-examples[(char>? #\A #\a)
|
||||
(char>? #\a #\A)
|
||||
(char>? #\c #\b #\a)]}
|
||||
|
||||
@defproc[(char>=? [char1 char?] [char2 char?] ...+) boolean?]{
|
||||
@char-sort["nonincreasing" #f]
|
||||
|
||||
@examples[(char>=? #\A #\a)
|
||||
(char>=? #\a #\A)
|
||||
(char>=? #\c #\b #\b)]}
|
||||
@mz-examples[(char>=? #\A #\a)
|
||||
(char>=? #\a #\A)
|
||||
(char>=? #\c #\b #\b)]}
|
||||
|
||||
|
||||
@defproc[(char-ci=? [char1 char?] [char2 char?] ...+) boolean?]{
|
||||
Returns @scheme[#t] if all of the arguments are @scheme[eqv?] after
|
||||
locale-insensitive case-folding via @scheme[char-foldcase].
|
||||
|
||||
@examples[(char-ci=? #\A #\a)
|
||||
(char-ci=? #\a #\a #\a)]}
|
||||
@mz-examples[(char-ci=? #\A #\a)
|
||||
(char-ci=? #\a #\a #\a)]}
|
||||
|
||||
@defproc[(char-ci<? [char1 char?] [char2 char?] ...+) boolean?]{
|
||||
Like @scheme[char<?], but checks whether the arguments would be in
|
||||
increasing order if each was first case-folded using
|
||||
@scheme[char-foldcase] (which is locale-insensitive).
|
||||
|
||||
@examples[(char-ci<? #\A #\a)
|
||||
(char-ci<? #\a #\b)
|
||||
(char-ci<? #\a #\b #\c)]}
|
||||
@mz-examples[(char-ci<? #\A #\a)
|
||||
(char-ci<? #\a #\b)
|
||||
(char-ci<? #\a #\b #\c)]}
|
||||
|
||||
@defproc[(char-ci<=? [char1 char?] [char2 char?] ...+) boolean?]{
|
||||
@char-sort["nondecreasing" #t]
|
||||
|
||||
@examples[(char-ci<=? #\A #\a)
|
||||
(char-ci<=? #\a #\A)
|
||||
(char-ci<=? #\a #\b #\b)]}
|
||||
@mz-examples[(char-ci<=? #\A #\a)
|
||||
(char-ci<=? #\a #\A)
|
||||
(char-ci<=? #\a #\b #\b)]}
|
||||
|
||||
@defproc[(char-ci>? [char1 char?] [char2 char?] ...+) boolean?]{
|
||||
@char-sort["decreasing" #t]
|
||||
|
||||
@examples[(char-ci>? #\A #\a)
|
||||
(char-ci>? #\b #\A)
|
||||
(char-ci>? #\c #\b #\a)]}
|
||||
@mz-examples[(char-ci>? #\A #\a)
|
||||
(char-ci>? #\b #\A)
|
||||
(char-ci>? #\c #\b #\a)]}
|
||||
|
||||
@defproc[(char-ci>=? [char1 char?] [char2 char?] ...+) boolean?]{
|
||||
@char-sort["nonincreasing" #t]
|
||||
|
||||
@examples[(char-ci>=? #\A #\a)
|
||||
(char-ci>=? #\a #\A)
|
||||
(char-ci>=? #\c #\b #\b)]}
|
||||
@mz-examples[(char-ci>=? #\A #\a)
|
||||
(char-ci>=? #\a #\A)
|
||||
(char-ci>=? #\c #\b #\b)]}
|
||||
|
||||
@; ----------------------------------------
|
||||
@section{Classifications}
|
||||
|
@ -247,7 +247,7 @@ the case where Unicode defines a locale-independent mapping from the
|
|||
code point to a code-point sequence (in addition to the 1-1 mapping on
|
||||
scalar values).}
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(char-upcase #\a)
|
||||
(char-upcase #\u03BB)
|
||||
(char-upcase #\space)
|
||||
|
@ -258,7 +258,7 @@ scalar values).}
|
|||
|
||||
Like @scheme[char-upcase], but for the Unicode downcase mapping.
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(char-downcase #\A)
|
||||
(char-downcase #\u039B)
|
||||
(char-downcase #\space)
|
||||
|
@ -268,7 +268,7 @@ Like @scheme[char-upcase], but for the Unicode downcase mapping.
|
|||
|
||||
Like @scheme[char-upcase], but for the Unicode titlecase mapping.
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(char-upcase #\a)
|
||||
(char-upcase #\u03BB)
|
||||
(char-upcase #\space)
|
||||
|
@ -278,7 +278,7 @@ Like @scheme[char-upcase], but for the Unicode titlecase mapping.
|
|||
|
||||
Like @scheme[char-upcase], but for the Unicode case-folding mapping.
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(char-foldcase #\A)
|
||||
(char-foldcase #\u03A3)
|
||||
(char-foldcase #\u03c2)
|
||||
|
|
|
@ -13,6 +13,15 @@
|
|||
(require (for-label scheme))
|
||||
(provide (for-label (all-from-out scheme)))
|
||||
|
||||
(provide mz-examples)
|
||||
(define mz-eval (make-base-eval))
|
||||
(define-syntax mz-examples
|
||||
(syntax-rules ()
|
||||
[(_ #:eval . rest)
|
||||
(examples #:eval . rest)]
|
||||
[(_ . rest)
|
||||
(examples #:eval mz-eval . rest)]))
|
||||
|
||||
(define AllUnix "Unix and Mac OS X")
|
||||
(provide AllUnix)
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ noted above). Two numbers are @scheme[equal?] when they are
|
|||
@defproc[(number? [v any/c]) boolean?]{Returns @scheme[#t] if @scheme[v]
|
||||
is a number, @scheme[#f] otherwise.
|
||||
|
||||
@examples[(number? 1) (number? 2+3i) (number? "hello")]}
|
||||
@mz-examples[(number? 1) (number? 2+3i) (number? "hello")]}
|
||||
|
||||
|
||||
@defproc[(complex? [v any/c]) boolean?]{ Returns @scheme[(number? v)],
|
||||
|
@ -88,42 +88,42 @@ because all numbers are @tech{complex numbers}.}
|
|||
@defproc[(real? [v any/c]) boolean?]{ Returns @scheme[#t] if @scheme[v] is
|
||||
a @techlink{real number}, @scheme[#f] otherwise.
|
||||
|
||||
@examples[(real? 1) (real? +inf.0) (real? 2+3i)
|
||||
(real? 2+0.0i) (real? "hello")]}
|
||||
@mz-examples[(real? 1) (real? +inf.0) (real? 2+3i)
|
||||
(real? 2+0.0i) (real? "hello")]}
|
||||
|
||||
|
||||
@defproc[(rational? [v any/c]) boolean?]{ Returns @scheme[#t] if
|
||||
@scheme[v] is a @techlink{rational number}, @scheme[#f] otherwise.
|
||||
|
||||
@examples[(rational? 1) (rational? +inf.0) (real? "hello")]}
|
||||
@mz-examples[(rational? 1) (rational? +inf.0) (real? "hello")]}
|
||||
|
||||
|
||||
@defproc[(integer? [v any/c]) boolean?]{ Returns @scheme[#t] if @scheme[v]
|
||||
is a number that is an @techlink{integer}, @scheme[#f] otherwise.
|
||||
|
||||
@examples[(integer? 1) (integer? 2.3) (integer? 4.0) (integer? +inf.0)
|
||||
(integer? 2+3i) (integer? "hello")]}
|
||||
@mz-examples[(integer? 1) (integer? 2.3) (integer? 4.0) (integer? +inf.0)
|
||||
(integer? 2+3i) (integer? "hello")]}
|
||||
|
||||
|
||||
@defproc[(exact-integer? [v any/c]) boolean?]{
|
||||
|
||||
Returns @scheme[(and (integer? v) (exact? v))].
|
||||
|
||||
@examples[(exact-integer? 1) (exact-integer? 4.0)]}
|
||||
@mz-examples[(exact-integer? 1) (exact-integer? 4.0)]}
|
||||
|
||||
|
||||
@defproc[(exact-nonnegative-integer? [v any/c]) boolean?]{
|
||||
|
||||
Returns @scheme[(and (exact-integer? v) (not (negative? v)))].
|
||||
|
||||
@examples[(exact-nonnegative-integer? 0) (exact-nonnegative-integer? -1)]}
|
||||
@mz-examples[(exact-nonnegative-integer? 0) (exact-nonnegative-integer? -1)]}
|
||||
|
||||
|
||||
@defproc[(exact-positive-integer? [v any/c]) boolean?]{
|
||||
|
||||
Returns @scheme[(and (exact-integer? v) (positive? v))].
|
||||
|
||||
@examples[(exact-positive-integer? 1) (exact-positive-integer? 0)]}
|
||||
@mz-examples[(exact-positive-integer? 1) (exact-positive-integer? 0)]}
|
||||
|
||||
|
||||
@defproc[(inexact-real? [v any/c]) boolean?]{
|
||||
|
@ -139,40 +139,40 @@ otherwise.}
|
|||
|
||||
@defproc[(zero? [z number?]) boolean?]{ Returns @scheme[(= 0 z)].
|
||||
|
||||
@examples[(zero? 0) (zero? -0.0)]}
|
||||
@mz-examples[(zero? 0) (zero? -0.0)]}
|
||||
|
||||
|
||||
@defproc[(positive? [x real?]) boolean?]{ Returns @scheme[(> x 0)].
|
||||
|
||||
@examples[(positive? 10) (positive? -10) (positive? 0.0)]}
|
||||
@mz-examples[(positive? 10) (positive? -10) (positive? 0.0)]}
|
||||
|
||||
|
||||
@defproc[(negative? [x real?]) boolean?]{ Returns @scheme[(< x 0)].
|
||||
|
||||
@examples[(negative? 10) (negative? -10) (negative? -0.0)]}
|
||||
@mz-examples[(negative? 10) (negative? -10) (negative? -0.0)]}
|
||||
|
||||
|
||||
@defproc[(even? [n integer?]) boolean?]{ Returns @scheme[(zero? (modulo
|
||||
n 2))].
|
||||
|
||||
@examples[(even? 10.0) (even? 11) (even? +inf.0)]}
|
||||
@mz-examples[(even? 10.0) (even? 11) (even? +inf.0)]}
|
||||
|
||||
|
||||
@defproc[(odd? [n integer?]) boolean?]{ Returns @scheme[(not (even? n))].
|
||||
|
||||
@examples[(odd? 10.0) (odd? 11) (odd? +inf.0)]}
|
||||
@mz-examples[(odd? 10.0) (odd? 11) (odd? +inf.0)]}
|
||||
|
||||
|
||||
@defproc[(exact? [z number?]) boolean?]{ Returns @scheme[#t] if @scheme[z]
|
||||
is an exact number, @scheme[#f] otherwise.
|
||||
|
||||
@examples[(exact? 1) (exact? 1.0)]}
|
||||
@mz-examples[(exact? 1) (exact? 1.0)]}
|
||||
|
||||
|
||||
@defproc[(inexact? [z number?]) boolean?]{ Returns @scheme[#t] if @scheme[z]
|
||||
is an inexact number, @scheme[#f] otherwise.
|
||||
|
||||
@examples[(inexact? 1) (inexact? 1.0)]}
|
||||
@mz-examples[(inexact? 1) (inexact? 1.0)]}
|
||||
|
||||
|
||||
@defproc[(inexact->exact [z number?]) exact?]{ Coerces @scheme[z] to an
|
||||
|
@ -180,13 +180,13 @@ otherwise.}
|
|||
is @scheme[+inf.0], @scheme[-inf.0], or @scheme[+nan.0], then the
|
||||
@exnraise[exn:fail:contract].
|
||||
|
||||
@examples[(inexact->exact 1) (inexact->exact 1.0)]}
|
||||
@mz-examples[(inexact->exact 1) (inexact->exact 1.0)]}
|
||||
|
||||
|
||||
@defproc[(exact->inexact [z number?]) inexact?]{ Coerces @scheme[z] to an
|
||||
inexact number. If @scheme[z] is already inexact, it is returned.
|
||||
|
||||
@examples[(exact->inexact 1) (exact->inexact 1.0)]}
|
||||
@mz-examples[(exact->inexact 1) (exact->inexact 1.0)]}
|
||||
|
||||
|
||||
@; ----------------------------------------
|
||||
|
@ -196,7 +196,7 @@ otherwise.}
|
|||
@scheme[z]s, adding pairwise from left to right. If no arguments are
|
||||
provided, the result is @scheme[0].
|
||||
|
||||
@examples[(+ 1 2) (+ 1.0 2+3i 5) (+)]}
|
||||
@mz-examples[(+ 1 2) (+ 1.0 2+3i 5) (+)]}
|
||||
|
||||
|
||||
@defproc*[([(- [z number?]) number?]
|
||||
|
@ -205,14 +205,14 @@ otherwise.}
|
|||
Otherwise, returns the subtraction of the @scheme[w]s from @scheme[z]
|
||||
working pairwise from left to right.}
|
||||
|
||||
@examples[(- 5 3.0) (- 1) (- 2+7i 1 3)]
|
||||
@mz-examples[(- 5 3.0) (- 1) (- 2+7i 1 3)]
|
||||
|
||||
|
||||
@defproc[(* [z number?] ...) number?]{ Returns the product of the
|
||||
@scheme[z]s, multiplying pairwise from left to right. If no arguments are
|
||||
provided, the result is @scheme[1].}
|
||||
|
||||
@examples[(* 2 3) (* 8.0 9) (* 1+2i 3+4i)]
|
||||
@mz-examples[(* 2 3) (* 8.0 9) (* 1+2i 3+4i)]
|
||||
|
||||
|
||||
@defproc*[([(/ [z number?]) number?]
|
||||
|
@ -221,13 +221,13 @@ otherwise.}
|
|||
Otherwise, returns the division @scheme[z] by the var[w]s
|
||||
working pairwise from left to right.}
|
||||
|
||||
@examples[(/ 3 4) (/ 81 3 3) (/ 10.0) (/ 1+2i 3+4i)]
|
||||
@mz-examples[(/ 3 4) (/ 81 3 3) (/ 10.0) (/ 1+2i 3+4i)]
|
||||
|
||||
|
||||
@defproc[(quotient [n integer?] [m integer?]) integer?]{ Returns
|
||||
@scheme[(truncate (/ n m))].}
|
||||
|
||||
@examples[(quotient 10 3) (quotient -10.0 3) (quotient +inf.0 3)]
|
||||
@mz-examples[(quotient 10 3) (quotient -10.0 3) (quotient +inf.0 3)]
|
||||
|
||||
|
||||
@defproc[(remainder [n integer?] [m integer?]) integer?]{ Returns
|
||||
|
@ -241,14 +241,14 @@ otherwise.}
|
|||
|
||||
}
|
||||
|
||||
@examples[(remainder 10 3) (remainder -10.0 3) (remainder 10.0 -3) (remainder -10 -3) (remainder +inf.0 3)]}
|
||||
@mz-examples[(remainder 10 3) (remainder -10.0 3) (remainder 10.0 -3) (remainder -10 -3) (remainder +inf.0 3)]}
|
||||
|
||||
|
||||
@defproc[(quotient/remainder [n integer?] [m integer?]) (values number? number?)]{ Returns
|
||||
@scheme[(values (quotient n m) (remainder n m))], but the combination is computed
|
||||
more efficiently than separate calls to @scheme[quotient] and @scheme[remainder].
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(quotient/remainder 10 3)
|
||||
]}
|
||||
|
||||
|
@ -264,7 +264,7 @@ otherwise.}
|
|||
|
||||
}
|
||||
|
||||
@examples[(modulo 10 3) (modulo -10.0 3) (modulo 10.0 -3) (modulo -10 -3) (modulo +inf.0 3)]}
|
||||
@mz-examples[(modulo 10 3) (modulo -10.0 3) (modulo 10.0 -3) (modulo -10 -3) (modulo +inf.0 3)]}
|
||||
|
||||
|
||||
@defproc[(add1 [z number?]) number?]{ Returns @scheme[(+ z 1)].}
|
||||
|
@ -274,20 +274,20 @@ otherwise.}
|
|||
@defproc[(abs [x real?]) number?]{ Returns the absolute value of
|
||||
@scheme[x].
|
||||
|
||||
@examples[(abs 1.0) (abs -1)]}
|
||||
@mz-examples[(abs 1.0) (abs -1)]}
|
||||
|
||||
@defproc[(max [x real?] ...+) boolean?]{ Returns the largest of the
|
||||
@scheme[x]s, or @scheme[+nan.0] if any @scheme[x] is @scheme[+nan.0].
|
||||
If any @scheme[x] is inexact, the result is coerced to inexact.
|
||||
|
||||
@examples[(max 1 3 2) (max 1 3 2.0)]}
|
||||
@mz-examples[(max 1 3 2) (max 1 3 2.0)]}
|
||||
|
||||
|
||||
@defproc[(min [x real?] ...+) boolean?]{ Returns the smallest of the
|
||||
@scheme[x]s, or @scheme[+nan.0] if any @scheme[x] is @scheme[+nan.0].
|
||||
If any @scheme[x] is inexact, the result is coerced to inexact.
|
||||
|
||||
@examples[(min 1 3 2) (min 1 3 2.0)]}
|
||||
@mz-examples[(min 1 3 2) (min 1 3 2.0)]}
|
||||
|
||||
|
||||
@defproc[(gcd [n integer?] ...) integer?]{ Returns the
|
||||
|
@ -295,7 +295,7 @@ otherwise.}
|
|||
@scheme[n]s. If no arguments are provided, the result is
|
||||
@scheme[0]. If all arguments are zero, the result is zero.
|
||||
|
||||
@examples[(gcd 10) (gcd 12 81.0)]}
|
||||
@mz-examples[(gcd 10) (gcd 12 81.0)]}
|
||||
|
||||
|
||||
@defproc[(lcm [n integer?] ...) integer?]{ Returns the @as-index{least
|
||||
|
@ -303,31 +303,31 @@ otherwise.}
|
|||
arguments are provided, the result is @scheme[1]. If any argument is
|
||||
zero, the result is zero.
|
||||
|
||||
@examples[(lcm 10) (lcm 3 4.0)]}
|
||||
@mz-examples[(lcm 10) (lcm 3 4.0)]}
|
||||
|
||||
|
||||
@defproc[(round [x real?]) integer?]{ Returns the integer closest to
|
||||
@scheme[x], resolving ties in favor of an even number.
|
||||
|
||||
@examples[(round 17/4) (round -17/4) (round 2.5) (round -2.5)]}
|
||||
@mz-examples[(round 17/4) (round -17/4) (round 2.5) (round -2.5)]}
|
||||
|
||||
|
||||
@defproc[(floor [x real?]) integer?]{ Returns the largest integer is that
|
||||
is no more than @scheme[x].
|
||||
|
||||
@examples[(floor 17/4) (floor -17/4) (floor 2.5) (floor -2.5)]}
|
||||
@mz-examples[(floor 17/4) (floor -17/4) (floor 2.5) (floor -2.5)]}
|
||||
|
||||
|
||||
@defproc[(ceiling [x real?]) integer?]{ Returns the smallest integer is
|
||||
that is at least as large as @scheme[x].
|
||||
|
||||
@examples[(ceiling 17/4) (ceiling -17/4) (ceiling 2.5) (ceiling -2.5)]}
|
||||
@mz-examples[(ceiling 17/4) (ceiling -17/4) (ceiling 2.5) (ceiling -2.5)]}
|
||||
|
||||
|
||||
@defproc[(truncate [x real?]) integer?]{ Returns the integer farthest
|
||||
from @scheme[0] that is no closer to @scheme[0] than @scheme[x].
|
||||
|
||||
@examples[(truncate 17/4) (truncate -17/4) (truncate 2.5) (truncate -2.5)]}
|
||||
@mz-examples[(truncate 17/4) (truncate -17/4) (truncate 2.5) (truncate -2.5)]}
|
||||
|
||||
|
||||
@defproc[(numerator [q rational?]) integer?]{
|
||||
|
@ -335,7 +335,7 @@ otherwise.}
|
|||
expressed in its simplest fractional form, and returns this number
|
||||
coerced to the exactness of @scheme[q].
|
||||
|
||||
@examples[(numerator 5) (numerator 34/8) (numerator 2.3)]}
|
||||
@mz-examples[(numerator 5) (numerator 34/8) (numerator 2.3)]}
|
||||
|
||||
|
||||
@defproc[(denominator [q rational?]) integer?]{
|
||||
|
@ -343,7 +343,7 @@ otherwise.}
|
|||
expressed in its simplest fractional form, and returns this number
|
||||
coerced to the exactness of @scheme[q].
|
||||
|
||||
@examples[(denominator 5) (denominator 34/8) (denominator 2.3)]}
|
||||
@mz-examples[(denominator 5) (denominator 34/8) (denominator 2.3)]}
|
||||
|
||||
|
||||
@defproc[(rationalize [x real?][tolerance real?]) real?]{
|
||||
|
@ -354,7 +354,7 @@ returns the one corresponding to an exact number whose
|
|||
@scheme[tolerance] of @scheme[x], the one closest to @scheme[0] is
|
||||
used.
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(rationalize 1/4 1/10)
|
||||
(rationalize -1/4 1/10)
|
||||
(rationalize 1/4 1/4)
|
||||
|
@ -371,35 +371,35 @@ used.
|
|||
exact number. Also, @scheme[0.0] and @scheme[-0.0] are numerically
|
||||
equal, but @scheme[+nan.0] is not numerically equal to itself.
|
||||
|
||||
@examples[(= 1 1.0) (= 1 2) (= 2+3i 2+3i 2+3i)]}
|
||||
@mz-examples[(= 1 1.0) (= 1 2) (= 2+3i 2+3i 2+3i)]}
|
||||
|
||||
|
||||
@defproc[(< [x real?] [y real?] ...+) boolean?]{ Returns @scheme[#t] if
|
||||
the arguments in the given order are in strictly increasing,
|
||||
@scheme[#f] otherwise.
|
||||
|
||||
@examples[(< 1 1) (< 1 2 3) (< 1 +inf.0) (< 1 +nan.0)]}
|
||||
@mz-examples[(< 1 1) (< 1 2 3) (< 1 +inf.0) (< 1 +nan.0)]}
|
||||
|
||||
|
||||
@defproc[(<= [x real?] [y real?] ...+) boolean?]{ Returns @scheme[#t]
|
||||
if the arguments in the given order are in non-decreasing,
|
||||
@scheme[#f] otherwise.
|
||||
|
||||
@examples[(<= 1 1) (<= 1 2 1)]}
|
||||
@mz-examples[(<= 1 1) (<= 1 2 1)]}
|
||||
|
||||
|
||||
@defproc[(> [x real?] [y real?] ...+) boolean?]{ Returns @scheme[#t] if
|
||||
the arguments in the given order are in strictly decreasing,
|
||||
@scheme[#f] otherwise.
|
||||
|
||||
@examples[(> 1 1) (> 3 2 1) (> +inf.0 1) (< +nan.0 1)]}
|
||||
@mz-examples[(> 1 1) (> 3 2 1) (> +inf.0 1) (< +nan.0 1)]}
|
||||
|
||||
|
||||
@defproc[(>= [x real?] [y real?] ...+) boolean?]{ Returns @scheme[#t]
|
||||
if the arguments in the given order are in non-increasing,
|
||||
@scheme[#f] otherwise.
|
||||
|
||||
@examples[(>= 1 1) (>= 1 2 1)]}
|
||||
@mz-examples[(>= 1 1) (>= 1 2 1)]}
|
||||
|
||||
|
||||
@; ------------------------------------------------------------------------
|
||||
|
@ -410,14 +410,14 @@ used.
|
|||
@scheme[z] is exact and @scheme[z]'s square root is rational. See
|
||||
also @scheme[integer-sqrt].
|
||||
|
||||
@examples[(sqrt 4/9) (sqrt 2) (sqrt -1)]}
|
||||
@mz-examples[(sqrt 4/9) (sqrt 2) (sqrt -1)]}
|
||||
|
||||
|
||||
@defproc[(integer-sqrt [n integer?]) complex?]{ Returns @scheme[(floor
|
||||
(sqrt n))] for positive @scheme[n]. For negative @scheme[n], the result is
|
||||
@scheme[(* (integer-sqrt (- n)) 0+i)].
|
||||
|
||||
@examples[(integer-sqrt 4.0) (integer-sqrt 5)]}
|
||||
@mz-examples[(integer-sqrt 4.0) (integer-sqrt 5)]}
|
||||
|
||||
|
||||
@defproc[(integer-sqrt/remainder [n integer?])
|
||||
|
@ -425,27 +425,27 @@ used.
|
|||
Returns @scheme[(integer-sqrt n)] and @scheme[(- n (expt
|
||||
(integer-sqrt n) 2))].
|
||||
|
||||
@examples[(integer-sqrt/remainder 4.0) (integer-sqrt/remainder 5)]}
|
||||
@mz-examples[(integer-sqrt/remainder 4.0) (integer-sqrt/remainder 5)]}
|
||||
|
||||
@defproc[(expt [z number?] [w number?]) number?]{ Returns @scheme[z]
|
||||
raised to the power of @scheme[w]. If @scheme[w] is exact @scheme[0],
|
||||
the result is @scheme[1]. If @scheme[z] is exact @scheme[0] and
|
||||
@scheme[w] is negative, the @exnraise[exn:fail:contract].
|
||||
|
||||
@examples[(expt 2 3) (expt 4 0.5) (expt +inf.0 0)]}
|
||||
@mz-examples[(expt 2 3) (expt 4 0.5) (expt +inf.0 0)]}
|
||||
|
||||
@defproc[(exp [z number?]) number?]{ Returns Euler's number raised to the
|
||||
power of @scheme[z]. The result is normally inexact, but it is
|
||||
@scheme[1] when @scheme[z] is an exact @scheme[0].
|
||||
|
||||
@examples[(exp 1) (exp 2+3i) (exp 0)]}
|
||||
@mz-examples[(exp 1) (exp 2+3i) (exp 0)]}
|
||||
|
||||
|
||||
@defproc[(log [z number?]) number?]{ Returns the natural logarithm of
|
||||
@scheme[z]. The result is normally inexact, but it is
|
||||
@scheme[0] when @scheme[z] is an exact @scheme[1].
|
||||
|
||||
@examples[(log (exp 1)) (log 2+3i) (log 1)]}
|
||||
@mz-examples[(log (exp 1)) (log 2+3i) (log 1)]}
|
||||
|
||||
|
||||
@; ------------------------------------------------------------------------
|
||||
|
@ -454,30 +454,30 @@ used.
|
|||
@defproc[(sin [z number?]) number?]{ Returns the sine of @scheme[z], where
|
||||
@scheme[z] is in radians.
|
||||
|
||||
@examples[(sin 3.14159) (sin 1+05.i)]}
|
||||
@mz-examples[(sin 3.14159) (sin 1+05.i)]}
|
||||
|
||||
|
||||
@defproc[(cos [z number?]) number?]{ Returns the cosine of @scheme[z],
|
||||
where @scheme[z] is in radians.
|
||||
|
||||
@examples[(cos 3.14159) (cos 1+05.i)]}
|
||||
@mz-examples[(cos 3.14159) (cos 1+05.i)]}
|
||||
|
||||
|
||||
@defproc[(tan [z number?]) number?]{ Returns the tangent of @scheme[z],
|
||||
where @scheme[z] is in radians.
|
||||
|
||||
@examples[(tan 0.7854) (tan 1+05.i)]}
|
||||
@mz-examples[(tan 0.7854) (tan 1+05.i)]}
|
||||
|
||||
|
||||
@defproc[(asin [z number?]) number?]{ Returns the arcsin in radians of @scheme[z].
|
||||
|
||||
@examples[(asin 0.25) (asin 1+05.i)]}
|
||||
@mz-examples[(asin 0.25) (asin 1+05.i)]}
|
||||
|
||||
|
||||
@defproc[(acos [z number?]) number?]{ Returns the arccosine in radians
|
||||
of @scheme[z].
|
||||
|
||||
@examples[(acos 0.25) (acos 1+05.i)]}
|
||||
@mz-examples[(acos 0.25) (acos 1+05.i)]}
|
||||
|
||||
|
||||
@defproc*[([(atan [z number?]) number?]
|
||||
|
@ -494,7 +494,7 @@ suitable angle is returned when @scheme[y] divided by @scheme[x]
|
|||
produces @scheme[+nan.0] in the case that neither @scheme[y] nor
|
||||
@scheme[x] is @scheme[+nan.0].
|
||||
|
||||
@examples[(atan 0.5) (atan 2 1) (atan -2 -1) (atan 1+05.i) (atan +inf.0 -inf.0)]}
|
||||
@mz-examples[(atan 0.5) (atan 2 1) (atan -2 -1) (atan 1+05.i) (atan +inf.0 -inf.0)]}
|
||||
|
||||
@; ------------------------------------------------------------------------
|
||||
@section{Complex Numbers}
|
||||
|
@ -502,38 +502,38 @@ produces @scheme[+nan.0] in the case that neither @scheme[y] nor
|
|||
@defproc[(make-rectangular [x real?] [y real?]) number?]{ Returns
|
||||
@scheme[(+ x (* y 0+1i))].
|
||||
|
||||
@examples[(make-rectangular 3 4.0)]}
|
||||
@mz-examples[(make-rectangular 3 4.0)]}
|
||||
|
||||
|
||||
@defproc[(make-polar [magnitude real?] [angle real?]) number?]{ Returns
|
||||
@scheme[(+ (* magnitude (cos angle)) (* magnitude (sin angle) 0+1i))].
|
||||
|
||||
@examples[(make-polar 2 3.14159)]}
|
||||
@mz-examples[(make-polar 2 3.14159)]}
|
||||
|
||||
|
||||
@defproc[(real-part [z number?]) real?]{ Returns the real part of
|
||||
the complex number @scheme[z] in rectangle coordinates.
|
||||
|
||||
@examples[(real-part 3+4i) (real-part 5.0)]}
|
||||
@mz-examples[(real-part 3+4i) (real-part 5.0)]}
|
||||
|
||||
|
||||
@defproc[(imag-part [z number?]) real?]{ Returns the imaginary part of
|
||||
the complex number @scheme[z] in rectangle coordinates.
|
||||
|
||||
@examples[(imag-part 3+4i) (imag-part 5.0) (imag-part 5.0+0.0i)]}
|
||||
@mz-examples[(imag-part 3+4i) (imag-part 5.0) (imag-part 5.0+0.0i)]}
|
||||
|
||||
|
||||
@defproc[(magnitude [z number?]) (and/c real? (not/c negative?))]{
|
||||
Returns the magnitude of the complex number @scheme[z] in polar
|
||||
coordinates.
|
||||
|
||||
@examples[(magnitude -3) (magnitude 3.0) (magnitude 3+4i)]}
|
||||
@mz-examples[(magnitude -3) (magnitude 3.0) (magnitude 3+4i)]}
|
||||
|
||||
|
||||
@defproc[(angle [z number?]) real?]{ Returns the angle of
|
||||
the complex number @scheme[z] in polar coordinates.
|
||||
|
||||
@examples[(angle -3) (angle 3.0) (angle 3+4i) (angle +inf.0+inf.0i)]}
|
||||
@mz-examples[(angle -3) (angle 3.0) (angle 3+4i) (angle +inf.0+inf.0i)]}
|
||||
|
||||
@; ------------------------------------------------------------------------
|
||||
@section{Bitwise Operations}
|
||||
|
@ -545,7 +545,7 @@ produces @scheme[+nan.0] in the case that neither @scheme[y] nor
|
|||
two's complement representation. If no arguments are provided, the
|
||||
result is @scheme[0].
|
||||
|
||||
@examples[(bitwise-ior 1 2) (bitwise-ior -32 1)]}
|
||||
@mz-examples[(bitwise-ior 1 2) (bitwise-ior -32 1)]}
|
||||
|
||||
|
||||
@defproc[(bitwise-and [n exact-integer?] ...) exact-integer?]{ Returns
|
||||
|
@ -553,7 +553,7 @@ produces @scheme[+nan.0] in the case that neither @scheme[y] nor
|
|||
complement representation. If no arguments are provided, the result
|
||||
is @scheme[-1].
|
||||
|
||||
@examples[(bitwise-and 1 2) (bitwise-and -32 -1)]}
|
||||
@mz-examples[(bitwise-and 1 2) (bitwise-and -32 -1)]}
|
||||
|
||||
|
||||
@defproc[(bitwise-xor [n exact-integer?] ...) exact-integer?]{ Returns
|
||||
|
@ -561,14 +561,14 @@ produces @scheme[+nan.0] in the case that neither @scheme[y] nor
|
|||
two's complement representation. If no arguments are provided, the
|
||||
result is @scheme[0].
|
||||
|
||||
@examples[(bitwise-xor 1 5) (bitwise-xor -32 -1)]}
|
||||
@mz-examples[(bitwise-xor 1 5) (bitwise-xor -32 -1)]}
|
||||
|
||||
|
||||
@defproc[(bitwise-not [n exact-integer?]) exact-integer?]{ Returns the
|
||||
bitwise ``not'' of @scheme[n] in its (semi-infinite) two's complement
|
||||
representation.
|
||||
|
||||
@examples[(bitwise-not 5) (bitwise-not -1)]}
|
||||
@mz-examples[(bitwise-not 5) (bitwise-not -1)]}
|
||||
|
||||
|
||||
@defproc[(bitwise-bit-set? [n exact-integer?] [m exact-nonnegative-integer?])
|
||||
|
@ -577,7 +577,7 @@ produces @scheme[+nan.0] in the case that neither @scheme[y] nor
|
|||
Returns @scheme[(not (zero? (bitwise-and n (arithmetic-shift 1 m))))],
|
||||
but normally without allocating intermediate results.
|
||||
|
||||
@examples[(bitwise-bit-set? 5 0) (bitwise-bit-set? 5 2) (bitwise-bit-set? -5 (expt 2 700))]}
|
||||
@mz-examples[(bitwise-bit-set? 5 0) (bitwise-bit-set? 5 2) (bitwise-bit-set? -5 (expt 2 700))]}
|
||||
|
||||
|
||||
@defproc[(arithmetic-shift [n exact-integer?] [m exact-integer?])
|
||||
|
@ -588,14 +588,14 @@ but normally without allocating intermediate results.
|
|||
@scheme[m] is negative, @scheme[n] is shifted right by @scheme[(- m)]
|
||||
bits; i.e., the rightmost @scheme[m] digits are dropped.
|
||||
|
||||
@examples[(arithmetic-shift 1 10) (arithmetic-shift 255 -3)]}
|
||||
@mz-examples[(arithmetic-shift 1 10) (arithmetic-shift 255 -3)]}
|
||||
|
||||
@defproc[(integer-length [n exact-integer?]) exact-integer?]{ Returns
|
||||
the number of bits in the (semi-infinite) two's complement
|
||||
representation of @scheme[n] after removing all leading zeros (for
|
||||
non-negative @scheme[n]) or ones (for negative @scheme[n]).
|
||||
|
||||
@examples[(integer-length 8) (integer-length -8)]}
|
||||
@mz-examples[(integer-length 8) (integer-length -8)]}
|
||||
|
||||
@; ------------------------------------------------------------------------
|
||||
@section{Random Numbers}
|
||||
|
@ -693,7 +693,7 @@ generator.}
|
|||
@scheme[radix] must be @scheme[10], otherwise the
|
||||
@exnraise[exn:fail:contract].
|
||||
|
||||
@examples[(number->string 3.0) (number->string 255 8)]}
|
||||
@mz-examples[(number->string 3.0) (number->string 255 8)]}
|
||||
|
||||
|
||||
@defproc[(string->number [s string?] [radix (integer-in 2 16) 10])
|
||||
|
@ -706,7 +706,7 @@ parse exactly as a number datum (with no whitespace). The optional
|
|||
which can be overriden by @litchar{#b}, @litchar{#o}, @litchar{#d}, or
|
||||
@litchar{#x} in the string.
|
||||
|
||||
@examples[(string->number "3.0+2.5i") (string->number "hello")
|
||||
@mz-examples[(string->number "3.0+2.5i") (string->number "hello")
|
||||
(string->number "111" 7) (string->number "#b111" 7)]
|
||||
}
|
||||
|
||||
|
@ -725,7 +725,7 @@ process is an exact number whose decimal representation has no more
|
|||
than @scheme[decimal-digits] digits after the decimal (and it is
|
||||
padded with trailing zeros if necessary).
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
#:eval math-eval
|
||||
(real->decimal-string pi)
|
||||
(real->decimal-string pi 5)
|
||||
|
@ -843,7 +843,7 @@ Returns @scheme[(* z z)].}
|
|||
Returns the sign of @scheme[x] as either @math{-1}, @math{0}, or
|
||||
@math{1}.
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
#:eval math-eval
|
||||
(sgn 10)
|
||||
(sgn -10.0)
|
||||
|
@ -854,7 +854,7 @@ Returns the sign of @scheme[x] as either @math{-1}, @math{0}, or
|
|||
|
||||
Returns the complex conjugate of @scheme[z].
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
#:eval math-eval
|
||||
(conjugate 1)
|
||||
(conjugate 3+4i)
|
||||
|
|
|
@ -106,7 +106,7 @@ integers from @scheme[0] to @scheme[(sub1 n)] in order. If
|
|||
@scheme[_lst] is the resulting list, then @scheme[(list-ref _lst _i)]
|
||||
is the value produced by @scheme[(proc _i)].
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(build-list 10 values)
|
||||
(build-list 5 (lambda (x) (* x x)))
|
||||
]}
|
||||
|
@ -191,7 +191,7 @@ Similar to @scheme[map], except that
|
|||
|
||||
If the @scheme[lst]s are empty, then @scheme[#t] is returned.}
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(andmap positive? '(1 2 3))
|
||||
(andmap positive? '(1 2 a))
|
||||
(andmap positive? '(1 -2 a))
|
||||
|
@ -220,7 +220,7 @@ Similar to @scheme[map], except that
|
|||
|
||||
If the @scheme[lst]s are empty, then @scheme[#f] is returned.}
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(ormap eq? '(a b c) '(a b c))
|
||||
(ormap positive? '(1 2 a))
|
||||
(ormap + '(1 2 3) '(4 5 6))
|
||||
|
@ -257,7 +257,7 @@ If @scheme[foldl] is called with @math{n} lists, then @scheme[proc]
|
|||
Unlike @scheme[foldr], @scheme[foldl] processes the @scheme[lst]s in
|
||||
constant space (plus the space for each call to @scheme[proc]).
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(foldl cons '() '(1 2 3 4))
|
||||
(foldl + 0 '(1 2 3 4))
|
||||
]}
|
||||
|
@ -270,7 +270,7 @@ Like @scheme[foldl], but the lists are traversed from right to left.
|
|||
space proportional to the length of @scheme[lst]s (plus the space for
|
||||
each call to @scheme[proc]).
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(foldr cons '() '(1 2 3 4))
|
||||
(foldr (lambda (v l) (cons (add1 v) l)) '() '(1 2 3 4))
|
||||
]}
|
||||
|
@ -365,7 +365,7 @@ By default, @scheme[extract-key] is applied to two list elements for
|
|||
@scheme[extract-key] as @scheme[(lambda (x) (random))] and
|
||||
@scheme[#t] for @scheme[cache-keys?] effectively shuffles the list.}
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(sort '(1 3 4 2) <)
|
||||
(sort '("aardvark" "dingo" "cow" "bear") string<?)
|
||||
(sort '(("aardvark") ("dingo") ("cow") ("bear"))
|
||||
|
@ -521,7 +521,7 @@ Returns a fresh list whose elements are the first @scheme[pos] elements of
|
|||
The @scheme[lst] argument need not actually be a list; @scheme[lst]
|
||||
must merely start with a chain of at least @scheme[pos] pairs.
|
||||
|
||||
@examples[#:eval list-eval
|
||||
@mz-examples[#:eval list-eval
|
||||
(take '(1 2 3 4) 2)
|
||||
(take 'non-list 0)
|
||||
]}
|
||||
|
@ -545,7 +545,7 @@ has fewer than @scheme[pos] elements, then the
|
|||
The @scheme[lst] argument need not actually be a list; @scheme[lst]
|
||||
must merely end with a chain of at least @scheme[pos] pairs.
|
||||
|
||||
@examples[#:eval list-eval
|
||||
@mz-examples[#:eval list-eval
|
||||
(take-right '(1 2 3 4) 2)
|
||||
(take-right 'non-list 0)
|
||||
]}
|
||||
|
@ -558,7 +558,7 @@ dropping its @scheme[pos]-length tail. If @scheme[lst] has fewer than
|
|||
The @scheme[lst] argument need not actually be a list; @scheme[lst]
|
||||
must merely end with a chain of at least @scheme[pos] pairs.
|
||||
|
||||
@examples[#:eval list-eval
|
||||
@mz-examples[#:eval list-eval
|
||||
(drop-right '(1 2 3 4) 2)
|
||||
(drop-right 'non-list 0)
|
||||
]}
|
||||
|
@ -576,7 +576,7 @@ except that it can be faster.}
|
|||
Returns a list with the same elements as @scheme[lst], but with
|
||||
@scheme[v] between each pair of items in @scheme[lst].
|
||||
|
||||
@examples[#:eval list-eval
|
||||
@mz-examples[#:eval list-eval
|
||||
(add-between '(x y z) 'or)
|
||||
(add-between '(x) 'or)
|
||||
]}
|
||||
|
@ -591,7 +591,7 @@ same as @scheme[(apply append lst ... lsts)]. In other words, the
|
|||
relationship between @scheme[append] and @scheme[append*] is similar
|
||||
to the one between @scheme[list] and @scheme[list*].
|
||||
|
||||
@examples[#:eval list-eval
|
||||
@mz-examples[#:eval list-eval
|
||||
(append* '(a) '(b) '((c) (d)))
|
||||
(cdr (append* (map (lambda (x) (list ", " x))
|
||||
'("Alpha" "Beta" "Gamma"))))
|
||||
|
@ -606,7 +606,7 @@ pairs are interior nodes, and the resulting list contains all of the
|
|||
non-@scheme[null] leaves of the tree in the same order as an inorder
|
||||
traversal.
|
||||
|
||||
@examples[#:eval list-eval
|
||||
@mz-examples[#:eval list-eval
|
||||
(flatten '((a) b (c (d) . e) ()))
|
||||
(flatten 'a)
|
||||
]}
|
||||
|
@ -620,7 +620,7 @@ of the list are equivalent. The resulting list is in the same order
|
|||
as @scheme[lst], and for any item that occurs multiple times, the
|
||||
first one is kept.
|
||||
|
||||
@examples[#:eval list-eval
|
||||
@mz-examples[#:eval list-eval
|
||||
(remove-duplicates '(a b b a))
|
||||
(remove-duplicates '(1 2 1.0 0))
|
||||
(remove-duplicates '(1 2 1.0 0) =)
|
||||
|
@ -646,7 +646,7 @@ The result is the same as
|
|||
|
||||
but @scheme[pred] is applied to each item in @scheme[lst] only once.
|
||||
|
||||
@examples[#:eval list-eval
|
||||
@mz-examples[#:eval list-eval
|
||||
(partition even? '(1 2 3 4 5 6))
|
||||
]}
|
||||
|
||||
|
@ -656,7 +656,7 @@ but @scheme[pred] is applied to each item in @scheme[lst] only once.
|
|||
|
||||
Returns @scheme[(append* (map proc lst ...))].
|
||||
|
||||
@examples[#:eval list-eval
|
||||
@mz-examples[#:eval list-eval
|
||||
(append-map vector->list '(#(1) #(2 3) #(4)))
|
||||
]}
|
||||
|
||||
|
@ -668,7 +668,7 @@ Like @scheme[filter], but the meaning of the @scheme[pred] predicate
|
|||
is reversed: the result is a list of all items for which @scheme[pred]
|
||||
returns @scheme[#f].
|
||||
|
||||
@examples[#:eval list-eval
|
||||
@mz-examples[#:eval list-eval
|
||||
(filter-not even? '(1 2 3 4 5 6))
|
||||
]}
|
||||
|
||||
|
@ -714,7 +714,7 @@ placeholders:
|
|||
Due to these restrictions, @scheme[make-reader-graph] creates exactly
|
||||
the same sort of cyclic values as @scheme[read].
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(let* ([ph (make-placeholder #f)]
|
||||
[x (cons 1 ph)])
|
||||
(placeholder-set! ph x)
|
||||
|
|
|
@ -25,7 +25,7 @@ arguments; otherwise, the @exnraise[exn:fail:contract]. The given
|
|||
@scheme[proc] is called in tail position with respect to the
|
||||
@scheme[apply] call.
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(apply + '(1 2 3))
|
||||
(apply + 1 2 '(3))
|
||||
(apply + '())
|
||||
|
@ -40,7 +40,7 @@ composed functions can consume and produce any number of values, as
|
|||
long as each function produces as many values as the preceding
|
||||
function consumes.
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
((compose - sqrt) 10)
|
||||
((compose sqrt -) 10)
|
||||
((compose list split-path) (bytes->path #"/a" 'unix))
|
||||
|
@ -109,7 +109,7 @@ A valid arity @scheme[_a] is one of the following:
|
|||
|
||||
}
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(procedure-arity cons)
|
||||
(procedure-arity list)
|
||||
(arity-at-least? (procedure-arity list))
|
||||
|
@ -124,7 +124,7 @@ A valid arity @scheme[_a] is one of the following:
|
|||
Returns @scheme[#t] if the procedure can accept @scheme[k] arguments
|
||||
when no keyword arguments are supplied, @scheme[#f] otherwise.
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(procedure-arity-includes? cons 2)
|
||||
(procedure-arity-includes? display 3)
|
||||
]}
|
||||
|
@ -162,7 +162,7 @@ second result is a list of accepted keywords (sorted by
|
|||
accepted. When the second result is a list, every element in the first
|
||||
list is also in the second list.
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(procedure-keywords +)
|
||||
(procedure-keywords (lambda (#:tag t #:mode m) t))
|
||||
(procedure-keywords (lambda (#:tag t #:mode [m #f]) t))
|
||||
|
@ -303,7 +303,7 @@ Providing a procedure @scheme[proc-spec] argument to
|
|||
@scheme[prop:procedure] property (so that a specific property binding
|
||||
is disallowed).
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(define-struct fish (weight color)
|
||||
#:mutable
|
||||
#:property
|
||||
|
@ -414,7 +414,7 @@ applied.}
|
|||
Returns a procedure that is just like @scheme[proc], except that it
|
||||
returns the @scheme[not] of @scheme[proc]'s result.
|
||||
|
||||
@examples[#:eval fun-eval
|
||||
@mz-examples[#:eval fun-eval
|
||||
(filter (negate symbol?) '(1 a 2 b 3 c))
|
||||
(map (negate =) '(1 2 3) '(1 1 1))
|
||||
]}
|
||||
|
@ -427,7 +427,7 @@ the resulting procedure is first applied, unless it is given the
|
|||
maximum number of arguments that it can accept, the result is a
|
||||
procedure to accept additional arguments.
|
||||
|
||||
@examples[#:eval fun-eval
|
||||
@mz-examples[#:eval fun-eval
|
||||
((curry list) 1 2)
|
||||
((curry cons) 1)
|
||||
((curry cons) 1 2)
|
||||
|
@ -438,7 +438,7 @@ further application accumulates arguments until an acceptable number
|
|||
of arguments have been accumulated, at which point the original
|
||||
@scheme[proc] is called.
|
||||
|
||||
@examples[#:eval fun-eval
|
||||
@mz-examples[#:eval fun-eval
|
||||
(((curry list) 1 2) 3)
|
||||
(((curry list) 1) 3)
|
||||
((((curry foldl) +) 0) '(1 2 3))
|
||||
|
@ -452,7 +452,7 @@ The @scheme[curry] function provides limited support for keyworded
|
|||
functions: only the @scheme[curry] call itself can receive keyworded
|
||||
arguments to be propagated eventually to @scheme[proc].
|
||||
|
||||
@examples[#:eval fun-eval
|
||||
@mz-examples[#:eval fun-eval
|
||||
(map ((curry +) 10) '(1 2 3))
|
||||
(map (curry + 10) '(1 2 3))
|
||||
(map (compose (curry * 2) (curry + 10)) '(1 2 3))
|
||||
|
@ -469,7 +469,7 @@ Like @scheme[curry], except that the arguments are collected in the
|
|||
opposite direction: the first step collects the rightmost group of
|
||||
arguments, and following steps add arguments to the left of these.
|
||||
|
||||
@examples[#:eval fun-eval
|
||||
@mz-examples[#:eval fun-eval
|
||||
(map (curryr list 'foo) '(1 2 3))
|
||||
]}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ A string can be used as a single-valued sequence (see
|
|||
@secref["sequences"]). The characters of the string serve as elements
|
||||
of the sequence. See also @scheme[in-string].
|
||||
|
||||
See also: @scheme[immutable], @scheme[symbol->string],
|
||||
See also: @scheme[immutable?], @scheme[symbol->string],
|
||||
@scheme[bytes->string/utf-8].
|
||||
|
||||
@; ----------------------------------------
|
||||
|
@ -31,7 +31,7 @@ See also: @scheme[immutable], @scheme[symbol->string],
|
|||
@defproc[(string? [v any/c]) boolean?]{ Returns @scheme[#t] if @scheme[v]
|
||||
is a string, @scheme[#f] otherwise.
|
||||
|
||||
@examples[(string? "Apple") (string? 'apple)]}
|
||||
@mz-examples[(string? "Apple") (string? 'apple)]}
|
||||
|
||||
|
||||
@defproc[(make-string [k exact-nonnegative-integer?] [char char?
|
||||
|
@ -39,14 +39,14 @@ See also: @scheme[immutable], @scheme[symbol->string],
|
|||
each position in the string is initialized with the character
|
||||
@scheme[char].
|
||||
|
||||
@examples[(make-string 5 #\z)]}
|
||||
@mz-examples[(make-string 5 #\z)]}
|
||||
|
||||
|
||||
@defproc[(string [char char?] ...) string?]{ Returns a new
|
||||
mutable string whose length is the number of provided @scheme[char]s, and
|
||||
whose positions are initialized with the given @scheme[char]s.
|
||||
|
||||
@examples[(string #\A #\p #\p #\l #\e)]}
|
||||
@mz-examples[(string #\A #\p #\p #\l #\e)]}
|
||||
|
||||
|
||||
@defproc[(string->immutable-string [str string?]) (and/c string? immutable?)]{
|
||||
|
@ -58,7 +58,7 @@ Returns an immutable string with the same content as
|
|||
@defproc[(string-length [str string?]) exact-nonnegative-integer?]{
|
||||
Returns the length of @scheme[str].
|
||||
|
||||
@examples[(string-length "Apple")]}
|
||||
@mz-examples[(string-length "Apple")]}
|
||||
|
||||
|
||||
@defproc[(string-ref [str string?] [k exact-nonnegative-integer?])
|
||||
|
@ -67,7 +67,7 @@ Returns an immutable string with the same content as
|
|||
position @scheme[k] must be less than the length of the string,
|
||||
otherwise the @exnraise[exn:fail:contract].
|
||||
|
||||
@examples[(string-ref "Apple" 0)]}
|
||||
@mz-examples[(string-ref "Apple" 0)]}
|
||||
|
||||
|
||||
@defproc[(string-set! [str (and/c string? (not/c immutable?))] [k
|
||||
|
@ -91,8 +91,8 @@ Returns an immutable string with the same content as
|
|||
@scheme[str], and @scheme[end] must be greater than or equal to @scheme[str],
|
||||
otherwise the @exnraise[exn:fail:contract].
|
||||
|
||||
@examples[(substring "Apple" 1 3)
|
||||
(substring "Apple" 1)]}
|
||||
@mz-examples[(substring "Apple" 1 3)
|
||||
(substring "Apple" 1)]}
|
||||
|
||||
|
||||
@defproc[(string-copy [str string?]) string?]{ Returns
|
||||
|
@ -117,18 +117,18 @@ Returns an immutable string with the same content as
|
|||
account the sizes of the strings and the source and destination
|
||||
regions), the @exnraise[exn:fail:contract].
|
||||
|
||||
@examples[(define s (string #\A #\p #\p #\l #\e))
|
||||
(string-copy! s 4 "y")
|
||||
(string-copy! s 0 s 3 4)
|
||||
s]}
|
||||
@mz-examples[(define s (string #\A #\p #\p #\l #\e))
|
||||
(string-copy! s 4 "y")
|
||||
(string-copy! s 0 s 3 4)
|
||||
s]}
|
||||
|
||||
@defproc[(string-fill! [dest (and/c string? (not/c immutable?))] [char
|
||||
char?]) void?]{ Changes @scheme[dest] so that every position in the
|
||||
string is filled with @scheme[char].
|
||||
|
||||
@examples[(define s (string #\A #\p #\p #\l #\e))
|
||||
(string-fill! s #\q)
|
||||
s]}
|
||||
@mz-examples[(define s (string #\A #\p #\p #\l #\e))
|
||||
(string-fill! s #\q)
|
||||
s]}
|
||||
|
||||
|
||||
@defproc[(string-append [str string?] ...) string?]{
|
||||
|
@ -138,7 +138,7 @@ as long as the sum of the given @scheme[str]s' lengths, and that
|
|||
contains the concatenated characters of the given @scheme[str]s. If no
|
||||
@scheme[str]s are provided, the result is a zero-length string.
|
||||
|
||||
@examples[(string-append "Apple" "Banana")]}
|
||||
@mz-examples[(string-append "Apple" "Banana")]}
|
||||
|
||||
|
||||
@defproc[(string->list [str string?]) (listof char?)]{ Returns a new
|
||||
|
@ -147,7 +147,7 @@ contains the concatenated characters of the given @scheme[str]s. If no
|
|||
sequence of characters of @scheme[str] are in the same sequence in the
|
||||
result list.
|
||||
|
||||
@examples[(string->list "Apple")]}
|
||||
@mz-examples[(string->list "Apple")]}
|
||||
|
||||
|
||||
@defproc[(list->string [lst (listof char?)]) string?]{ Returns a new
|
||||
|
@ -156,7 +156,7 @@ contains the concatenated characters of the given @scheme[str]s. If no
|
|||
the sequence of characters in @scheme[lst] is in the same sequence in
|
||||
the result string.
|
||||
|
||||
@examples[(list->string (list #\A #\p #\p #\l #\e))]}
|
||||
@mz-examples[(list->string (list #\A #\p #\p #\l #\e))]}
|
||||
|
||||
|
||||
@defproc[(build-string [n exact-nonnegative-integer?]
|
||||
|
@ -168,7 +168,7 @@ the integers from @scheme[0] to @scheme[(sub1 n)] in order. If
|
|||
@scheme[_str] is the resulting string, then @scheme[(string-ref _str
|
||||
_i)] is the character produced by @scheme[(proc _i)].
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(build-string 5 (lambda (i) (integer->char (+ i 97))))
|
||||
]}
|
||||
|
||||
|
@ -180,8 +180,8 @@ _i)] is the character produced by @scheme[(proc _i)].
|
|||
@defproc[(string=? [str1 string?] [str2 string?] ...+) boolean?]{ Returns
|
||||
@scheme[#t] if all of the arguments are @scheme[equal?].}
|
||||
|
||||
@examples[(string=? "Apple" "apple")
|
||||
(string=? "a" "as" "a")]
|
||||
@mz-examples[(string=? "Apple" "apple")
|
||||
(string=? "a" "as" "a")]
|
||||
|
||||
@(define (string-sort direction folded?)
|
||||
(if folded?
|
||||
|
@ -193,68 +193,68 @@ _i)] is the character produced by @scheme[(proc _i)].
|
|||
increasing, where individual characters are ordered by
|
||||
@scheme[char<?], @scheme[#f] otherwise.
|
||||
|
||||
@examples[(string<? "Apple" "apple")
|
||||
(string<? "apple" "Apple")
|
||||
(string<? "a" "b" "c")]}
|
||||
@mz-examples[(string<? "Apple" "apple")
|
||||
(string<? "apple" "Apple")
|
||||
(string<? "a" "b" "c")]}
|
||||
|
||||
@defproc[(string<=? [str1 string?] [str2 string?] ...+) boolean?]{
|
||||
@string-sort["nondecreasing" #f]
|
||||
|
||||
@examples[(string<=? "Apple" "apple")
|
||||
(string<=? "apple" "Apple")
|
||||
(string<=? "a" "b" "b")]}
|
||||
@mz-examples[(string<=? "Apple" "apple")
|
||||
(string<=? "apple" "Apple")
|
||||
(string<=? "a" "b" "b")]}
|
||||
|
||||
@defproc[(string>? [str1 string?] [str2 string?] ...+) boolean?]{
|
||||
@string-sort["decreasing" #f]
|
||||
|
||||
@examples[(string>? "Apple" "apple")
|
||||
(string>? "apple" "Apple")
|
||||
(string>? "c" "b" "a")]}
|
||||
@mz-examples[(string>? "Apple" "apple")
|
||||
(string>? "apple" "Apple")
|
||||
(string>? "c" "b" "a")]}
|
||||
|
||||
@defproc[(string>=? [str1 string?] [str2 string?] ...+) boolean?]{
|
||||
@string-sort["nonincreasing" #f]
|
||||
|
||||
@examples[(string>=? "Apple" "apple")
|
||||
(string>=? "apple" "Apple")
|
||||
(string>=? "c" "b" "b")]}
|
||||
@mz-examples[(string>=? "Apple" "apple")
|
||||
(string>=? "apple" "Apple")
|
||||
(string>=? "c" "b" "b")]}
|
||||
|
||||
|
||||
@defproc[(string-ci=? [str1 string?] [str2 string?] ...+) boolean?]{
|
||||
Returns @scheme[#t] if all of the arguments are @scheme[eqv?] after
|
||||
locale-insensitive case-folding via @scheme[string-foldcase].
|
||||
|
||||
@examples[(string-ci=? "Apple" "apple")
|
||||
(string-ci=? "a" "a" "a")]}
|
||||
@mz-examples[(string-ci=? "Apple" "apple")
|
||||
(string-ci=? "a" "a" "a")]}
|
||||
|
||||
@defproc[(string-ci<? [str1 string?] [str2 string?] ...+) boolean?]{
|
||||
Like @scheme[string<?], but checks whether the arguments would be in
|
||||
increasing order if each was first case-folded using
|
||||
@scheme[string-foldcase] (which is locale-insensitive).
|
||||
|
||||
@examples[(string-ci<? "Apple" "apple")
|
||||
(string-ci<? "apple" "banana")
|
||||
(string-ci<? "a" "b" "c")]}
|
||||
@mz-examples[(string-ci<? "Apple" "apple")
|
||||
(string-ci<? "apple" "banana")
|
||||
(string-ci<? "a" "b" "c")]}
|
||||
|
||||
@defproc[(string-ci<=? [str1 string?] [str2 string?] ...+) boolean?]{
|
||||
@string-sort["nondecreasing" #t]
|
||||
|
||||
@examples[(string-ci<=? "Apple" "apple")
|
||||
(string-ci<=? "apple" "Apple")
|
||||
(string-ci<=? "a" "b" "b")]}
|
||||
@mz-examples[(string-ci<=? "Apple" "apple")
|
||||
(string-ci<=? "apple" "Apple")
|
||||
(string-ci<=? "a" "b" "b")]}
|
||||
|
||||
@defproc[(string-ci>? [str1 string?] [str2 string?] ...+) boolean?]{
|
||||
@string-sort["decreasing" #t]
|
||||
|
||||
@examples[(string-ci>? "Apple" "apple")
|
||||
(string-ci>? "banana" "Apple")
|
||||
(string-ci>? "c" "b" "a")]}
|
||||
@mz-examples[(string-ci>? "Apple" "apple")
|
||||
(string-ci>? "banana" "Apple")
|
||||
(string-ci>? "c" "b" "a")]}
|
||||
|
||||
@defproc[(string-ci>=? [str1 string?] [str2 string?] ...+) boolean?]{
|
||||
@string-sort["nonincreasing" #t]
|
||||
|
||||
@examples[(string-ci>=? "Apple" "apple")
|
||||
(string-ci>=? "apple" "Apple")
|
||||
(string-ci>=? "c" "b" "b")]}
|
||||
@mz-examples[(string-ci>=? "Apple" "apple")
|
||||
(string-ci>=? "apple" "Apple")
|
||||
(string-ci>=? "c" "b" "b")]}
|
||||
|
||||
@; ----------------------------------------
|
||||
@section{String Conversions}
|
||||
|
@ -267,7 +267,7 @@ _i)] is the character produced by @scheme[(proc _i)].
|
|||
over the string), so the string produced by the conversion can be
|
||||
longer than the input string.
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(string-upcase "abc!")
|
||||
(string-upcase "Stra\xDFe")
|
||||
]}
|
||||
|
@ -275,7 +275,7 @@ _i)] is the character produced by @scheme[(proc _i)].
|
|||
@defproc[(string-downcase [string string?]) string?]{ Like
|
||||
@scheme[string-upcase], but the downcase conversion.
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(string-downcase "aBC!")
|
||||
(string-downcase "Stra\xDFe")
|
||||
(string-downcase "\u039A\u0391\u039F\u03A3")
|
||||
|
@ -288,7 +288,7 @@ _i)] is the character produced by @scheme[(proc _i)].
|
|||
first character in each sequence of cased characters in @scheme[str]
|
||||
(ignoring case-ignorable characters).
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(string-titlecase "aBC twO")
|
||||
(string-titlecase "y2k")
|
||||
(string-titlecase "main stra\xDFe")
|
||||
|
@ -298,7 +298,7 @@ _i)] is the character produced by @scheme[(proc _i)].
|
|||
@defproc[(string-foldcase [string string?]) string?]{ Like
|
||||
@scheme[string-upcase], but the case-folding conversion.
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(string-foldcase "aBC!")
|
||||
(string-foldcase "Stra\xDFe")
|
||||
(string-foldcase "\u039A\u0391\u039F\u03A3")
|
||||
|
@ -377,7 +377,7 @@ str ... strs)] is the same as @scheme[(apply string-append str
|
|||
@scheme[string-append] and @scheme[string-append*] is similar to the
|
||||
one between @scheme[list] and @scheme[list*].
|
||||
|
||||
@examples[#:eval string-eval
|
||||
@mz-examples[#:eval string-eval
|
||||
(string-append* "a" "b" '("c" "d"))
|
||||
(string-append* (cdr (append* (map (lambda (x) (list ", " x))
|
||||
'("Alpha" "Beta" "Gamma")))))
|
||||
|
@ -388,7 +388,7 @@ one between @scheme[list] and @scheme[list*].
|
|||
Appends the strings in @scheme[strs], inserting @scheme[sep] between
|
||||
each pair of strings in @scheme[strs].
|
||||
|
||||
@examples[#:eval string-eval
|
||||
@mz-examples[#:eval string-eval
|
||||
(string-join '("one" "two" "three" "four") " potato ")
|
||||
]}
|
||||
|
||||
|
|
|
@ -800,7 +800,7 @@ representation of the program fragment) without its @tech{lexical
|
|||
information}, source location, etc. Quoted pairs, vectors, and boxes
|
||||
are immutable.
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(eval:alts (#,(schemekeywordfont "quote") x) 'x)
|
||||
(eval:alts (#,(schemekeywordfont "quote") (+ 1 2)) '(+ 1 2))
|
||||
(+ 1 2)
|
||||
|
@ -817,7 +817,7 @@ syntax error is reported.
|
|||
See also @secref["expand-steps"] for information on how the expander
|
||||
introduces @schemeidfont{#%datum} identifiers.
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(#%datum . 10)
|
||||
(#%datum . x)
|
||||
(#%datum . #:x)
|
||||
|
@ -833,7 +833,7 @@ Produces the same result as @scheme[expr]. The only use of
|
|||
@scheme[#%expression] is to force the parsing of a form as an
|
||||
expression.
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(#%expression (+ 1 2))
|
||||
(#%expression (define x 10))
|
||||
]}
|
||||
|
@ -920,7 +920,7 @@ arguments). Typically, the lexical context of the pair indicates the
|
|||
procedure-application @scheme[#%app] that is described next. See also
|
||||
@secref["expand-steps"].
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(+ 1 2)
|
||||
((lambda (x #:arg y) (list y x)) #:arg 2 1)
|
||||
]}
|
||||
|
@ -959,7 +959,7 @@ according to their order in the application form.
|
|||
See also @secref["expand-steps"] for information on how the
|
||||
expander introduces @schemeidfont{#%app} identifiers.
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(#%app + 1 2)
|
||||
(#%app (lambda (x #:arg y) (list y x)) #:arg 2 1)
|
||||
(#%app cons)
|
||||
|
@ -1077,7 +1077,7 @@ the @exnraise[exn:fail:contract].
|
|||
The last @scheme[body] expression is in tail position with respect to
|
||||
the procedure body.
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
((lambda (x) x) 10)
|
||||
((lambda (x y) (list y x)) 1 2)
|
||||
((lambda (x [y 5]) (list y x)) 1 2)
|
||||
|
@ -1117,7 +1117,7 @@ Note that a @scheme[case-lambda] clause supports only
|
|||
@scheme[lambda]. That is, @scheme[case-lambda] does not directly
|
||||
support keyword and optional arguments.
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(let ([f (case-lambda
|
||||
[() 10]
|
||||
[(x) x]
|
||||
|
@ -1148,7 +1148,7 @@ locations. It then evaluates the @scheme[body]s, in which the
|
|||
tail position with respect to the @scheme[let] form. The @scheme[id]s
|
||||
must be distinct according to @scheme[bound-identifier=?].
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(let ([x 5]) x)
|
||||
(let ([x 5])
|
||||
(let ([x 2]
|
||||
|
@ -1161,7 +1161,7 @@ values become arguments in an application of a procedure
|
|||
@scheme[(lambda (id ...) body ...+)], where @scheme[proc-id] is bound
|
||||
within the @scheme[body]s to the procedure itself.}
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(let fac ([n 10])
|
||||
(if (zero? n)
|
||||
1
|
||||
|
@ -1176,7 +1176,7 @@ available. The @scheme[id]s are bound in the remaining @scheme[val-expr]s
|
|||
as well as the @scheme[body]s, and the @scheme[id]s need not be
|
||||
distinct; later bindings shadow earlier bindings.
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(let* ([x 1]
|
||||
[y (+ x 1)])
|
||||
(list y x))
|
||||
|
@ -1190,7 +1190,7 @@ created first and filled with @|undefined-const|, and all
|
|||
@scheme[body]s. The @scheme[id]s must be distinct according to
|
||||
@scheme[bound-identifier=?].
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(letrec ([is-even? (lambda (n)
|
||||
(or (zero? n)
|
||||
(is-odd? (sub1 n))))]
|
||||
|
@ -1206,7 +1206,7 @@ values as corresponding @scheme[id]s, otherwise the
|
|||
@exnraise[exn:fail:contract]. A separate location is created for each
|
||||
@scheme[id], all of which are bound in the @scheme[body]s.
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(let-values ([(x y) (quotient/remainder 10 3)])
|
||||
(list y x))
|
||||
]}
|
||||
|
@ -1217,7 +1217,7 @@ values as corresponding @scheme[id]s. A separate location is created
|
|||
for each @scheme[id], all of which are bound in the later
|
||||
@scheme[val-expr]s and in the @scheme[body]s.
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(let*-values ([(x y) (quotient/remainder 10 3)]
|
||||
[(z) (list y x)])
|
||||
z)
|
||||
|
@ -1230,7 +1230,7 @@ created for each @scheme[id], all of which are initialized to
|
|||
@|undefined-const| and bound in all @scheme[val-expr]s
|
||||
and in the @scheme[body]s.
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(letrec-values ([(is-even? is-odd?)
|
||||
(values
|
||||
(lambda (n)
|
||||
|
@ -1319,7 +1319,7 @@ evaluated, and its results are the result for the @scheme[if]
|
|||
form. The @scheme[then-expr] and @scheme[else-expr] are in tail
|
||||
position with respect to the @scheme[if] form.
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(if (positive? -5) (error "doesn't get here") 2)
|
||||
(if (positive? 5) 1 (error "doesn't get here"))
|
||||
]}
|
||||
|
@ -1368,7 +1368,7 @@ the @scheme[cond] expression.}
|
|||
returned as the result of the @scheme[cond] form. The
|
||||
@scheme[test-expr] is not in tail position.}
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(cond)
|
||||
(cond
|
||||
[else 5])
|
||||
|
@ -1411,7 +1411,7 @@ Otherwise, the first @scheme[expr] is evaluated. If it produces
|
|||
expression with the remaining @scheme[expr]s in tail position with
|
||||
respect to the original @scheme[and] form.
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(and)
|
||||
(and 1)
|
||||
(and (values 1 2))
|
||||
|
@ -1435,7 +1435,7 @@ value other than @scheme[#f], that result is the result of the
|
|||
@scheme[or] expression with the remaining @scheme[expr]s in tail
|
||||
position with respect to the original @scheme[or] form.
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(or)
|
||||
(or 1)
|
||||
(or (values 1 2))
|
||||
|
@ -1466,7 +1466,7 @@ For the selected @scheme[case-clause], the results of the last
|
|||
A @scheme[case-clause] that starts with @scheme[else] must be the last
|
||||
@scheme[case-clause].
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(case (+ 7 5)
|
||||
[(1 2 3) 'small]
|
||||
[(10 11 12) 'big])
|
||||
|
@ -1681,7 +1681,7 @@ ignoring the @scheme[body] results. The results of the @scheme[expr]
|
|||
are the results of the @scheme[begin0] form, but the @scheme[expr] is
|
||||
in tail position only if no @scheme[body]s are present.
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(begin0
|
||||
(values 1 2)
|
||||
(printf "hi\n"))
|
||||
|
@ -1725,7 +1725,7 @@ the result of the @scheme[when] expression is
|
|||
last @scheme[expr] is in tail position with respect to the
|
||||
@scheme[when] form.
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(when (positive? -5)
|
||||
(display "hi"))
|
||||
(when (positive? 5)
|
||||
|
@ -1737,7 +1737,7 @@ last @scheme[expr] is in tail position with respect to the
|
|||
|
||||
Equivalent to @scheme[(when (not test-expr) expr ...)].
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(unless (positive? 5)
|
||||
(display "hi"))
|
||||
(unless (positive? -5)
|
||||
|
@ -1788,7 +1788,7 @@ Assuming that all @scheme[id]s refer to variables, this form evaluates
|
|||
corresponding value from @scheme[expr] in the same way as for
|
||||
@scheme[set!].
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(let ([a 1]
|
||||
[b 2])
|
||||
(set!-values (a b) (values b a))
|
||||
|
@ -1851,7 +1851,7 @@ is used directly in place of the quoted pair (in the same way that
|
|||
@scheme[quasiquote] in any other way than as @scheme[(unquote _expr)]
|
||||
or @scheme[(unquote-splicing _expr)], a syntax error is reported.
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(eval:alts (#,(scheme quasiquote) (0 1 2)) `(0 1 2))
|
||||
(eval:alts (#,(scheme quasiquote) (0 (#,(scheme unquote) (+ 1 2)) 4)) `(0 ,(+ 1 2) 4))
|
||||
(eval:alts (#,(scheme quasiquote) (0 (#,(scheme unquote-splicing) (list 1 2)) 4)) `(0 ,@(list 1 2) 4))
|
||||
|
@ -1863,7 +1863,7 @@ A @scheme[quasiquote], @scheme[unquote], or @scheme[unquote-splicing]
|
|||
form is typically abbreviated with @litchar{`}, @litchar{,}, or
|
||||
@litchar[",@"], respectively. See also @secref["parse-quote"].
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
`(0 1 2)
|
||||
`(1 ,(+ 1 2) 4)
|
||||
`#s(stuff 1 ,(+ 1 2) 4)
|
||||
|
@ -1878,7 +1878,7 @@ but a further nested @scheme[unquote] or @scheme[unquote-splicing]
|
|||
escapes. Multiple nestings of @scheme[quasiquote] require multiple
|
||||
nestings of @scheme[unquote] or @scheme[unquote-splicing] to escape.
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
`(1 `,(+ 1 ,(+ 2 3)) 4)
|
||||
`(1 ```,,@,,@(list (+ 1 2)) 4)
|
||||
]
|
||||
|
@ -1915,7 +1915,7 @@ Produces a @tech{syntax object} that preserves the @tech{lexical
|
|||
information} and source-location information attached to
|
||||
@scheme[datum] at expansion time.
|
||||
|
||||
@examples[
|
||||
@mz-examples[
|
||||
(syntax? (quote-syntax x))
|
||||
]
|
||||
}
|
||||
|
|
|
@ -512,9 +512,26 @@
|
|||
(lambda () #f))
|
||||
#f))))
|
||||
|
||||
(define (make-prod-thread)
|
||||
;; periodically dumps a stack trace, which can give us some idea of
|
||||
;; what the main thread is doing; usually used in `render-time'.
|
||||
(let ([t (current-thread)])
|
||||
(thread (lambda ()
|
||||
(let loop ()
|
||||
(sleep 0.05)
|
||||
(for-each (lambda (i)
|
||||
(printf "~s\n" i))
|
||||
(continuation-mark-set->context (continuation-marks t)))
|
||||
(newline)
|
||||
(loop))))))
|
||||
|
||||
(define-syntax-rule (render-time what expr)
|
||||
expr
|
||||
#;
|
||||
(begin
|
||||
(printf "For ~a\n" what)
|
||||
(time expr))
|
||||
#;
|
||||
(begin
|
||||
(collect-garbage) (collect-garbage) (printf "pre: ~a ~s\n" what (current-memory-use))
|
||||
(begin0
|
||||
|
|
|
@ -263,16 +263,19 @@ Use syntax/modcollapse instead.
|
|||
(if path
|
||||
(collapse-module-path
|
||||
path
|
||||
(cond
|
||||
[(module-path-index? base)
|
||||
(collapse-module-path-index base relto-mp)]
|
||||
[(resolved-module-path? base)
|
||||
(let ([n (resolved-module-path-name base)])
|
||||
(if (path? n)
|
||||
n
|
||||
relto-mp))]
|
||||
[else relto-mp]))
|
||||
relto-mp)))
|
||||
(lambda ()
|
||||
(cond
|
||||
[(module-path-index? base)
|
||||
(collapse-module-path-index base relto-mp)]
|
||||
[(resolved-module-path? base)
|
||||
(let ([n (resolved-module-path-name base)])
|
||||
(if (path? n)
|
||||
n
|
||||
relto-mp))]
|
||||
[else relto-mp])))
|
||||
(if (procedure? relto-mp)
|
||||
(relto-mp)
|
||||
relto-mp))))
|
||||
|
||||
(provide collapse-module-path
|
||||
collapse-module-path-index)
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
(require mzlib/unitsig
|
||||
mzlib/list
|
||||
mzlib/string
|
||||
mzlib/etc)
|
||||
mzlib/etc
|
||||
(only scheme/base for for/fold in-list log-error))
|
||||
|
||||
(require "sig.ss")
|
||||
|
||||
|
@ -97,31 +98,36 @@
|
|||
;; write-xml-element : Element Nat (Nat Output-Stream -> Void) Output-Stream -> Void
|
||||
(define (write-xml-element el over dent out)
|
||||
(let* ([name (element-name el)]
|
||||
[start (lambda (f) (write-xml-base (format f name) over dent out))]
|
||||
[start (lambda (str)
|
||||
(write-xml-base str over dent out)
|
||||
(display name out))]
|
||||
[content (element-content el)])
|
||||
(start "<~a")
|
||||
(for-each (lambda (att)
|
||||
(fprintf out " ~a=\"~a\"" (attribute-name att)
|
||||
(escape (attribute-value att) escape-attribute-table)))
|
||||
(element-attributes el))
|
||||
(start "<")
|
||||
(for ([att (in-list (element-attributes el))])
|
||||
(fprintf out " ~a=\"~a\"" (attribute-name att)
|
||||
(escape (attribute-value att) escape-attribute-table)))
|
||||
(if (and (null? content)
|
||||
(let ([short (empty-tag-shorthand)])
|
||||
(case short
|
||||
[(always) #t]
|
||||
[(never) #f]
|
||||
[else (memq (lowercase-symbol name) short)])))
|
||||
(fprintf out " />")
|
||||
(display " />" out)
|
||||
(begin
|
||||
(fprintf out ">")
|
||||
(for-each (lambda (c) (write-xml-content c (incr over) dent out)) content)
|
||||
(start "</~a")
|
||||
(fprintf out ">")))))
|
||||
(display ">" out)
|
||||
(for ([c (in-list content)])
|
||||
(write-xml-content c (incr over) dent out))
|
||||
(start "</")
|
||||
(display ">" out)))))
|
||||
|
||||
; : sym -> sym
|
||||
(define lowercases (make-hash-table 'weak))
|
||||
(define (lowercase-symbol x)
|
||||
(let ([s (symbol->string x)])
|
||||
(string-lowercase! s)
|
||||
(string->symbol s)))
|
||||
(or (hash-table-get lowercases x #f)
|
||||
(let ([s (symbol->string x)])
|
||||
(let ([s (string->symbol (string-downcase s))])
|
||||
(hash-table-put! lowercases x s)
|
||||
s))))
|
||||
|
||||
;; write-xml-base : (U String Char Symbol) Nat (Nat Output-Stream -> Void) Output-Stream -> Void
|
||||
(define (write-xml-base el over dent out)
|
||||
|
@ -150,20 +156,19 @@
|
|||
(let ([n (entity-text entity)])
|
||||
(fprintf out (if (number? n) "&#~a;" "&~a;") n)))
|
||||
|
||||
(define escape-table
|
||||
(map (lambda (x y) (cons (regexp (symbol->string x)) y))
|
||||
'(< > &)
|
||||
'("\\<" "\\>" "\\&")))
|
||||
|
||||
(define escape-attribute-table
|
||||
(list* (cons (regexp "\"") "\\"") escape-table))
|
||||
(define escape-table #rx"[<>&]")
|
||||
(define escape-attribute-table #rx"[<>&\"]")
|
||||
|
||||
(define (replace-escaped s)
|
||||
(case (string-ref s 0)
|
||||
[(#\<) "<"]
|
||||
[(#\>) ">"]
|
||||
[(#\&) "&"]
|
||||
[(#\") """]))
|
||||
|
||||
;; escape : String -> String
|
||||
;; more here - this could be much more efficient
|
||||
(define (escape x table)
|
||||
(foldr (lambda (esc str) (regexp-replace* (car esc) str (cdr esc)))
|
||||
x
|
||||
table))
|
||||
(regexp-replace* table x replace-escaped))
|
||||
|
||||
;; incr : Nat -> Nat
|
||||
(define (incr n) (+ n 2)))))
|
||||
|
|
|
@ -202,7 +202,7 @@
|
|||
(f (map srep->attribute (cadr x)) (cddr x))
|
||||
(f null (cdr x))))]
|
||||
[(string? x) (make-pcdata 'scheme 'scheme x)]
|
||||
[(or (symbol? x) (and (integer? x) (>= x 0)))
|
||||
[(or (symbol? x) (exact-nonnegative-integer? x))
|
||||
(make-entity 'scheme 'scheme x)]
|
||||
[(or (comment? x) (pi? x) (cdata? x)) x]
|
||||
[else ;(error 'xexpr->xml "malformed xexpr ~e" x)
|
||||
|
|
|
@ -1349,6 +1349,11 @@ static int eq_testable_constant(Scheme_Object *v)
|
|||
if (SCHEME_CHARP(v) && (SCHEME_CHAR_VAL(v) < 256))
|
||||
return 1;
|
||||
|
||||
if (SCHEME_INTP(v)
|
||||
&& (SCHEME_INT_VAL(v) < (1 << 29))
|
||||
&& (SCHEME_INT_VAL(v) > -(1 << 29)))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -6814,6 +6814,10 @@ cont_marks(int argc, Scheme_Object *argv[])
|
|||
Scheme_Thread *t = (Scheme_Thread *)argv[0];
|
||||
Scheme_Object *m;
|
||||
|
||||
while (t->nestee) {
|
||||
t = t->nestee;
|
||||
}
|
||||
|
||||
if (SAME_OBJ(t, scheme_current_thread))
|
||||
return scheme_current_continuation_marks(prompt_tag);
|
||||
|
||||
|
@ -6833,6 +6837,8 @@ cont_marks(int argc, Scheme_Object *argv[])
|
|||
|
||||
return (Scheme_Object *)set;
|
||||
} else {
|
||||
scheme_start_atomic(); /* just in case */
|
||||
|
||||
t->return_marks_to = scheme_current_thread;
|
||||
t->returned_marks = prompt_tag;
|
||||
scheme_swap_thread(t);
|
||||
|
@ -6840,6 +6846,8 @@ cont_marks(int argc, Scheme_Object *argv[])
|
|||
m = t->returned_marks;
|
||||
t->returned_marks = NULL;
|
||||
|
||||
scheme_end_atomic_no_swap();
|
||||
|
||||
return m;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -3956,6 +3956,9 @@ void scheme_thread_block(float sleep_time)
|
|||
Scheme_Thread *next;
|
||||
Scheme_Thread *p = scheme_current_thread;
|
||||
|
||||
if (p->return_marks_to) /* just in case we get here */
|
||||
return;
|
||||
|
||||
if (p->running & MZTHREAD_KILLED) {
|
||||
/* This thread is dead! Give up now. */
|
||||
if (!do_atomic)
|
||||
|
|
Loading…
Reference in New Issue
Block a user