use @racket instead of @scheme in vector docs

This commit is contained in:
Sam Tobin-Hochstadt 2010-05-03 17:13:14 -04:00
parent 46828541a5
commit b752370a57

View File

@ -6,38 +6,38 @@
@guideintro["vectors"]{vectors} @guideintro["vectors"]{vectors}
A @deftech{vector} is a fixed-length array with constant-time access A @deftech{vector} is a fixed-length array with constant-time access
and update of the vector slots, which are numbered from @scheme[0] to and update of the vector slots, which are numbered from @racket[0] to
one less than the number of slots in the vector. one less than the number of slots in the vector.
Two vectors are @scheme[equal?] if they have the same length, and if Two vectors are @racket[equal?] if they have the same length, and if
the values in corresponding slots of the vectors are the values in corresponding slots of the vectors are
@scheme[equal?]. @racket[equal?].
A vector can be @defterm{mutable} or @defterm{immutable}. When an A vector can be @defterm{mutable} or @defterm{immutable}. When an
immutable vector is provided to a procedure like @scheme[vector-set!], immutable vector is provided to a procedure like @racket[vector-set!],
the @exnraise[exn:fail:contract]. Vectors generated by the default the @exnraise[exn:fail:contract]. Vectors generated by the default
reader (see @secref["parse-string"]) are immutable. reader (see @secref["parse-string"]) are immutable.
A vector can be used as a single-valued sequence (see A vector can be used as a single-valued sequence (see
@secref["sequences"]). The elements of the vector serve as elements @secref["sequences"]). The elements of the vector serve as elements
of the sequence. See also @scheme[in-vector]. of the sequence. See also @racket[in-vector].
@defproc[(vector? [v any/c]) boolean?]{ @defproc[(vector? [v any/c]) boolean?]{
Returns @scheme[#t] if @scheme[v] is a vector, @scheme[#f] otherwise.} Returns @racket[#t] if @racket[v] is a vector, @racket[#f] otherwise.}
@defproc[(make-vector [size exact-nonnegative-integer?] @defproc[(make-vector [size exact-nonnegative-integer?]
[v any/c 0]) vector?]{ [v any/c 0]) vector?]{
Returns a mutable vector with @scheme[size] slots, where all slots are Returns a mutable vector with @racket[size] slots, where all slots are
initialized to contain @scheme[v].} initialized to contain @racket[v].}
@defproc[(vector [v any/c] ...) vector?]{ @defproc[(vector [v any/c] ...) vector?]{
Returns a newly allocated mutable vector with as many slots as provided @scheme[v]s, Returns a newly allocated mutable vector with as many slots as provided @racket[v]s,
where the slots are initialized to contain the given @scheme[v]s in where the slots are initialized to contain the given @racket[v]s in
order.} order.}
@ -45,55 +45,55 @@ order.}
immutable?)]{ immutable?)]{
Returns a newly allocated immutable vector with as many slots as provided Returns a newly allocated immutable vector with as many slots as provided
@scheme[v]s, where the slots are contain the given @scheme[v]s in @racket[v]s, where the slots are contain the given @racket[v]s in
order.} order.}
@defproc[(vector-length [vec vector?]) exact-nonnegative-integer?]{ @defproc[(vector-length [vec vector?]) exact-nonnegative-integer?]{
Returns the length of @scheme[vec] (i.e., the number of slots in the Returns the length of @racket[vec] (i.e., the number of slots in the
vector).} vector).}
@defproc[(vector-ref [vec vector?][pos exact-nonnegative-integer?]) any/c]{ @defproc[(vector-ref [vec vector?][pos exact-nonnegative-integer?]) any/c]{
Returns the element in slot @scheme[pos] of @scheme[vec]. The first Returns the element in slot @racket[pos] of @racket[vec]. The first
slot is position @scheme[0], and the last slot is one less than slot is position @racket[0], and the last slot is one less than
@scheme[(vector-length vec)].} @racket[(vector-length vec)].}
@defproc[(vector-set! [vec (and/c vector? (not/c immutable?))] @defproc[(vector-set! [vec (and/c vector? (not/c immutable?))]
[pos exact-nonnegative-integer?] [pos exact-nonnegative-integer?]
[v any/c]) [v any/c])
void?]{ void?]{
Updates the slot @scheme[pos] of @scheme[vec] to contain @scheme[v].} Updates the slot @racket[pos] of @racket[vec] to contain @racket[v].}
@defproc[(vector->list [vec vector?]) @defproc[(vector->list [vec vector?])
list?]{ list?]{
Returns a list with the same length and elements as @scheme[vec].} Returns a list with the same length and elements as @racket[vec].}
@defproc[(list->vector [lst list?]) @defproc[(list->vector [lst list?])
vector?]{ vector?]{
Returns a mutable vector with the same length and elements as Returns a mutable vector with the same length and elements as
@scheme[lst].} @racket[lst].}
@defproc[(vector->immutable-vector [vec vector?]) @defproc[(vector->immutable-vector [vec vector?])
(and/c vector? immutable?)]{ (and/c vector? immutable?)]{
Returns an immutable vector with the same length and elements as @scheme[vec]. Returns an immutable vector with the same length and elements as @racket[vec].
If @scheme[vec] is itself immutable, then it is returned as the result.} If @racket[vec] is itself immutable, then it is returned as the result.}
@defproc[(vector-fill! [vec (and/c vector? (not/c immutable?))] @defproc[(vector-fill! [vec (and/c vector? (not/c immutable?))]
[v any/c]) [v any/c])
void?]{ void?]{
Changes all slots of @scheme[vec] to contain @scheme[v].} Changes all slots of @racket[vec] to contain @racket[v].}
@defproc[(vector-copy! [dest (and/c vector? (not/c immutable?))] @defproc[(vector-copy! [dest (and/c vector? (not/c immutable?))]
@ -103,14 +103,14 @@ Changes all slots of @scheme[vec] to contain @scheme[v].}
[src-end exact-nonnegative-integer? (vector-length src)]) [src-end exact-nonnegative-integer? (vector-length src)])
void?]{ void?]{
Changes the elements of @scheme[dest] starting at position Changes the elements of @racket[dest] starting at position
@scheme[dest-start] to match the elements in @scheme[src] from @racket[dest-start] to match the elements in @racket[src] from
@scheme[src-start] (inclusive) to @scheme[src-end] (exclusive). The @racket[src-start] (inclusive) to @racket[src-end] (exclusive). The
vectors @scheme[dest] and @scheme[src] can be the same vector, and in vectors @racket[dest] and @racket[src] can be the same vector, and in
that case the destination region can overlap with the source region; that case the destination region can overlap with the source region;
the destination elements after the copy match the source elements the destination elements after the copy match the source elements
from before the copy. If any of @scheme[dest-start], from before the copy. If any of @racket[dest-start],
@scheme[src-start], or @scheme[src-end] are out of range (taking into @racket[src-start], or @racket[src-end] are out of range (taking into
account the sizes of the vectors and the source and destination account the sizes of the vectors and the source and destination
regions), the @exnraise[exn:fail:contract]. regions), the @exnraise[exn:fail:contract].
@ -125,21 +125,21 @@ Changes all slots of @scheme[vec] to contain @scheme[v].}
[end-pos exact-nonnegative-integer? (vector-length vec)]) [end-pos exact-nonnegative-integer? (vector-length vec)])
any]{ any]{
Returns @math{@scheme[end-pos] - @scheme[start-pos]} values, which are Returns @math{@racket[end-pos] - @racket[start-pos]} values, which are
the elements of @scheme[vec] from @scheme[start-pos] (inclusive) to the elements of @racket[vec] from @racket[start-pos] (inclusive) to
@scheme[end-pos] (exclusive). If @scheme[start-pos] or @racket[end-pos] (exclusive). If @racket[start-pos] or
@scheme[end-pos] are greater than @scheme[(vector-length vec)], or if @racket[end-pos] are greater than @racket[(vector-length vec)], or if
@scheme[end-pos] is less than @scheme[start-pos], the @racket[end-pos] is less than @racket[start-pos], the
@exnraise[exn:fail:contract].} @exnraise[exn:fail:contract].}
@defproc[(build-vector [n exact-nonnegative-integer?] @defproc[(build-vector [n exact-nonnegative-integer?]
[proc (exact-nonnegative-integer? . -> . any/c)]) [proc (exact-nonnegative-integer? . -> . any/c)])
vector?]{ vector?]{
Creates a vector of @scheme[n] elements by applying @scheme[proc] to Creates a vector of @racket[n] elements by applying @racket[proc] to
the integers from @scheme[0] to @scheme[(sub1 n)] in order. If the integers from @racket[0] to @racket[(sub1 n)] in order. If
@scheme[_vec] is the resulting vector, then @scheme[(vector-ref _vec @racket[_vec] is the resulting vector, then @racket[(vector-ref _vec
_i)] is the value produced by @scheme[(proc _i)]. _i)] is the value produced by @racket[(proc _i)].
@examples[ @examples[
(build-vector 5 add1) (build-vector 5 add1)
@ -156,11 +156,11 @@ _i)] is the value produced by @scheme[(proc _i)].
@defproc[(vector-map [proc procedure?] [vec vector?] ...+) @defproc[(vector-map [proc procedure?] [vec vector?] ...+)
vector?]{ vector?]{
Applies @scheme[proc] to the elements of the @scheme[vec]s from the Applies @racket[proc] to the elements of the @racket[vec]s from the
first elements to the last. The @scheme[proc] argument must accept first elements to the last. The @racket[proc] argument must accept
the same number of arguments as the number of supplied @scheme[vec]s, the same number of arguments as the number of supplied @racket[vec]s,
and all @scheme[vec]s must have the same number of elements. The and all @racket[vec]s must have the same number of elements. The
result is a fresh vector containing each result of @scheme[proc] in result is a fresh vector containing each result of @racket[proc] in
order. order.
@mz-examples[#:eval vec-eval @mz-examples[#:eval vec-eval
@ -170,13 +170,13 @@ Applies @scheme[proc] to the elements of the @scheme[vec]s from the
@defproc[(vector-map! [proc procedure?] [vec vector?] ...+) @defproc[(vector-map! [proc procedure?] [vec vector?] ...+)
vector?]{ vector?]{
Applies @scheme[proc] to the elements of the @scheme[vec]s from the Applies @racket[proc] to the elements of the @racket[vec]s from the
first elements to the last. The @scheme[proc] argument must accept first elements to the last. The @racket[proc] argument must accept
the same number of arguments as the number of supplied @scheme[vec]s, the same number of arguments as the number of supplied @racket[vec]s,
and all @scheme[vec]s must have the same number of elements. The and all @racket[vec]s must have the same number of elements. The
each result of @scheme[proc] is inserted into the first @scheme[vec] each result of @racket[proc] is inserted into the first @racket[vec]
at the index that the arguments to @scheme[proc] was taken from. The at the index that the arguments to @racket[proc] was taken from. The
result is the first @scheme[vec]. result is the first @racket[vec].
@mz-examples[#:eval vec-eval @mz-examples[#:eval vec-eval
(define v #(1 2 3 4)) (define v #(1 2 3 4))
@ -195,36 +195,36 @@ of the elements of the given vectors in order.
@defproc[(vector-take [vec vector?] [pos exact-nonnegative-integer?]) vector?]{ @defproc[(vector-take [vec vector?] [pos exact-nonnegative-integer?]) vector?]{
Returns a fresh vector whose elements are the first @scheme[pos] elements of Returns a fresh vector whose elements are the first @racket[pos] elements of
@scheme[vec]. If @scheme[vec] has fewer than @racket[vec]. If @racket[vec] has fewer than
@scheme[pos] elements, then the @exnraise[exn:fail:contract]. @racket[pos] elements, then the @exnraise[exn:fail:contract].
@mz-examples[#:eval vec-eval @mz-examples[#:eval vec-eval
(vector-take #(1 2 3 4) 2) (vector-take #(1 2 3 4) 2)
]} ]}
@defproc[(vector-take-right [vec vector?] [pos exact-nonnegative-integer?]) vector?]{ @defproc[(vector-take-right [vec vector?] [pos exact-nonnegative-integer?]) vector?]{
Returns a fresh vector whose elements are the last @scheme[pos] elements of Returns a fresh vector whose elements are the last @racket[pos] elements of
@scheme[vec]. If @scheme[vec] has fewer than @racket[vec]. If @racket[vec] has fewer than
@scheme[pos] elements, then the @exnraise[exn:fail:contract]. @racket[pos] elements, then the @exnraise[exn:fail:contract].
@mz-examples[#:eval vec-eval @mz-examples[#:eval vec-eval
(vector-take-right #(1 2 3 4) 2) (vector-take-right #(1 2 3 4) 2)
]} ]}
@defproc[(vector-drop [vec vector?] [pos exact-nonnegative-integer?]) vector?]{ @defproc[(vector-drop [vec vector?] [pos exact-nonnegative-integer?]) vector?]{
Returns a fresh vector whose elements are the elements of @scheme[vec] Returns a fresh vector whose elements are the elements of @racket[vec]
after the first @scheme[pos] elements. If @scheme[vec] has fewer after the first @racket[pos] elements. If @racket[vec] has fewer
than @scheme[pos] elements, then the @exnraise[exn:fail:contract]. than @racket[pos] elements, then the @exnraise[exn:fail:contract].
@mz-examples[#:eval vec-eval @mz-examples[#:eval vec-eval
(vector-drop #(1 2 3 4) 2) (vector-drop #(1 2 3 4) 2)
]} ]}
@defproc[(vector-drop-right [vec vector?] [pos exact-nonnegative-integer?]) vector?]{ @defproc[(vector-drop-right [vec vector?] [pos exact-nonnegative-integer?]) vector?]{
Returns a fresh vector whose elements are the elements of @scheme[vec] Returns a fresh vector whose elements are the elements of @racket[vec]
before the first @scheme[pos] elements. If @scheme[vec] has fewer before the first @racket[pos] elements. If @racket[vec] has fewer
than @scheme[pos] elements, then the @exnraise[exn:fail:contract]. than @racket[pos] elements, then the @exnraise[exn:fail:contract].
@mz-examples[#:eval vec-eval @mz-examples[#:eval vec-eval
(vector-drop-right #(1 2 3 4) 2) (vector-drop-right #(1 2 3 4) 2)
@ -234,7 +234,7 @@ Returns a fresh vector whose elements are the elements of @scheme[vec]
(values vector? vector?)]{ (values vector? vector?)]{
Returns the same result as Returns the same result as
@schemeblock[(values (vector-take vec pos) (vector-drop vec pos))] @racketblock[(values (vector-take vec pos) (vector-drop vec pos))]
except that it can be faster. except that it can be faster.
@ -246,7 +246,7 @@ except that it can be faster.
(values vector? vector?)]{ (values vector? vector?)]{
Returns the same result as Returns the same result as
@schemeblock[(values (vector-take-right vec pos) (vector-drop-right vec pos))] @racketblock[(values (vector-take-right vec pos) (vector-drop-right vec pos))]
except that it can be faster. except that it can be faster.
@ -257,9 +257,9 @@ except that it can be faster.
@defproc[(vector-copy [vec vector?] [start exact-nonnegative-integer? @defproc[(vector-copy [vec vector?] [start exact-nonnegative-integer?
0] [end exact-nonnegative-integer? (vector-length v)]) vector?]{ 0] [end exact-nonnegative-integer? (vector-length v)]) vector?]{
Creates a fresh vector of size @scheme[(- end start)], with all of the Creates a fresh vector of size @racket[(- end start)], with all of the
elements of @scheme[vec] from @scheme[start] (inclusive) to elements of @racket[vec] from @racket[start] (inclusive) to
@scheme[end] (exclusive). @racket[end] (exclusive).
@mz-examples[#:eval vec-eval @mz-examples[#:eval vec-eval
(vector-copy #(1 2 3 4)) (vector-copy #(1 2 3 4))
@ -269,8 +269,8 @@ elements of @scheme[vec] from @scheme[start] (inclusive) to
} }
@defproc[(vector-filter [pred procedure?] [vec vector?]) vector?]{ @defproc[(vector-filter [pred procedure?] [vec vector?]) vector?]{
Returns a fresh vector with the elements of @scheme[vec] for which Returns a fresh vector with the elements of @racket[vec] for which
@scheme[pred] produces a true value. The @scheme[pred] procedure is @racket[pred] produces a true value. The @racket[pred] procedure is
applied to each element from first to last. applied to each element from first to last.
@mz-examples[#:eval vec-eval @mz-examples[#:eval vec-eval
@ -279,9 +279,9 @@ Returns a fresh vector with the elements of @scheme[vec] for which
@defproc[(vector-filter-not [pred procedure?] [vec vector?]) vector?]{ @defproc[(vector-filter-not [pred procedure?] [vec vector?]) vector?]{
Like @scheme[vector-filter], but the meaning of the @scheme[pred] predicate Like @racket[vector-filter], but the meaning of the @racket[pred] predicate
is reversed: the result is a vector of all items for which @scheme[pred] is reversed: the result is a vector of all items for which @racket[pred]
returns @scheme[#f]. returns @racket[#f].
@mz-examples[#:eval vec-eval @mz-examples[#:eval vec-eval
(vector-filter-not even? #(1 2 3 4 5 6)) (vector-filter-not even? #(1 2 3 4 5 6))
@ -291,8 +291,8 @@ returns @scheme[#f].
@defproc[(vector-count [proc procedure?] [vec vector?] ...+) @defproc[(vector-count [proc procedure?] [vec vector?] ...+)
exact-nonnegative-integer?]{ exact-nonnegative-integer?]{
Returns the number of elements of the @scheme[vec ...] (taken in Returns the number of elements of the @racket[vec ...] (taken in
parallel) on which @scheme[proc] does not evaluate to @scheme[#f]. parallel) on which @racket[proc] does not evaluate to @racket[#f].
@mz-examples[#:eval vec-eval @mz-examples[#:eval vec-eval
(vector-count even? #(1 2 3 4 5)) (vector-count even? #(1 2 3 4 5))
@ -302,8 +302,8 @@ parallel) on which @scheme[proc] does not evaluate to @scheme[#f].
@defproc[(vector-argmin [proc (-> any/c real?)] [vec vector?]) any/c]{ @defproc[(vector-argmin [proc (-> any/c real?)] [vec vector?]) any/c]{
This returns the first element in the non-empty vector @scheme[vec] that minimizes This returns the first element in the non-empty vector @racket[vec] that minimizes
the result of @scheme[proc]. the result of @racket[proc].
@mz-examples[#:eval vec-eval @mz-examples[#:eval vec-eval
(vector-argmin car #((3 pears) (1 banana) (2 apples))) (vector-argmin car #((3 pears) (1 banana) (2 apples)))
@ -313,8 +313,8 @@ the result of @scheme[proc].
@defproc[(vector-argmax [proc (-> any/c real?)] [vec vector?]) any/c]{ @defproc[(vector-argmax [proc (-> any/c real?)] [vec vector?]) any/c]{
This returns the first element in the non-empty vector @scheme[vec] that maximizes This returns the first element in the non-empty vector @racket[vec] that maximizes
the result of @scheme[proc]. the result of @racket[proc].
@mz-examples[#:eval vec-eval @mz-examples[#:eval vec-eval
(vector-argmax car #((3 pears) (1 banana) (2 apples))) (vector-argmax car #((3 pears) (1 banana) (2 apples)))
@ -328,9 +328,9 @@ the result of @scheme[proc].
@defproc[(vector-member [v any/c] [lst vector?]) @defproc[(vector-member [v any/c] [lst vector?])
(or/c natural-number/c #f)]{ (or/c natural-number/c #f)]{
Locates the first element of @scheme[vec] that is @scheme[equal?] to Locates the first element of @racket[vec] that is @racket[equal?] to
@scheme[v]. If such an element exists, the index of that element in @racket[v]. If such an element exists, the index of that element in
@scheme[vec] is returned. Otherwise, the result is @scheme[#f]. @racket[vec] is returned. Otherwise, the result is @racket[#f].
@mz-examples[ @mz-examples[
(vector-member 2 (vector 1 2 3 4)) (vector-member 2 (vector 1 2 3 4))
@ -341,7 +341,7 @@ Locates the first element of @scheme[vec] that is @scheme[equal?] to
@defproc[(vector-memv [v any/c] [vec vector?]) @defproc[(vector-memv [v any/c] [vec vector?])
(or/c natural-number/c #f)]{ (or/c natural-number/c #f)]{
Like @scheme[member], but finds an element using @scheme[eqv?]. Like @racket[member], but finds an element using @racket[eqv?].
@mz-examples[ @mz-examples[
(vector-memv 2 (vector 1 2 3 4)) (vector-memv 2 (vector 1 2 3 4))
(vector-memv 9 (vector 1 2 3 4)) (vector-memv 9 (vector 1 2 3 4))
@ -351,7 +351,7 @@ Like @scheme[member], but finds an element using @scheme[eqv?].
@defproc[(vector-memq [v any/c] [vec vector?]) @defproc[(vector-memq [v any/c] [vec vector?])
(or/c natural-number/c #f)]{ (or/c natural-number/c #f)]{
Like @scheme[member], but finds an element using @scheme[eq?]. Like @racket[member], but finds an element using @racket[eq?].
@mz-examples[ @mz-examples[
(vector-memq 2 (vector 1 2 3 4)) (vector-memq 2 (vector 1 2 3 4))