update docs

pull/2/head
Matthew Butterick 10 years ago
parent 84fe0e4de8
commit 3747a57c0e

@ -183,6 +183,7 @@ Predicates that report whether @racket[_v] can be coerced to the specified type.
@defproc[(coerce/symbol? [v any/c]) symbol?]
@defproc[(coerce/path? [v any/c]) path?]
@defproc[(coerce/boolean? [v any/c]) boolean?]
@defproc[(coerce/list? [v any/c]) list?]
)]
If @racket[_v] can be coerced to the specified type, change it to that type, then return it. If not, raise the usual contract error. These contracts can be used with input or output values.

@ -51,3 +51,32 @@ But be careful — in the example below, the result of the @racket[if] expressi
(report x)]
@defform[(report* expr ...)]
Applies @racket[report] separately to each @racket[_expr] in the list.
@defform[(repeat num expr ...)]
Evaluates @racket[_expr] repeatedly — @racket[_num] times, in fact — and returns the last value.
@examples[#:eval my-eval
(repeat 1000
(for/sum ([i (in-range 1000)]) i))
]
@defform[(time-repeat num expr ...)]
Shorthand for using @racket[time] with @racket[repeat]. Repeats the whole list of expressions and returns the total time.
@examples[#:eval my-eval
(time-repeat 1000
(for/product ([i (in-range 1000)]) i)
(for/sum ([i (in-range 1000)]) i))
]
@defform[(time-repeat* num expr ...)]
Applies @racket[time-repeat] to each @racket[_expr] individually.
@examples[#:eval my-eval
(time-repeat* 1000
(for/product ([i (in-range 1000)]) i)
(for/sum ([i (in-range 1000)]) i))
]

@ -121,3 +121,37 @@ Convert @racket[_values] to a simple list.
(split-at '(a b c d e f) 3)
(values->list (split-at '(a b c d e f) 3))
]
@defproc[
(sublist
[lst list?]
[start-idx (and/c integer? (not/c negative?))]
[end-idx (and/c integer? (not/c negative?))])
list?]
Return a sublist of the @racket[_lst] starting with item @racket[_start-idx] and ending one item @bold{before} item @racket[_end-idx]. (Similar to how list slices are denominated in Python.) Thus the maximum value for @racket[_end-idx] is @racketfont{(length @racket[_lst])}. Errors will be triggered by nonsensical values for @racket[_end-idx].
@examples[#:eval my-eval
(sublist '(0 1 2 3 4 5 6 7 8) 0 8)
(sublist '(0 1 2 3 4 5 6 7 8) 8 9)
(sublist '(0 1 2 3 4 5 6 7 8) 2 5)
(sublist '(0 1 2 3 4 5 6 7 8) 5 2)
(sublist '(0 1 2 3 4 5 6 7 8) 2 10)
]
@defproc[
(break-at
[lst list?]
[indexes (or/c integer? (listof? integer?))])
(listof list?)]
Break @racket[_lst] into smaller lists at the index positions in @racket[_indexes]. If a single integer value is given for @racket[_indexes], it's treated as a one-element list. Error if a breakpoint index exceeds the length of the list, or if the breakpoints are not increasing.
@examples[#:eval my-eval
(break-at '(0 1 2 3 4 5 6 7 8) 3)
(break-at '(0 1 2 3 4 5 6 7 8) '(3))
(break-at '(0 1 2 3 4 5 6 7 8) '(3 6))
(break-at '(0 1 2 3 4 5 6 7 8) '(3 6 8))
(break-at '(0 1 2 3 4 5 6 7 8) '(3 6 8 10))
]
Loading…
Cancel
Save