fix docs on `case'
The Guide was was out-of-date in several ways, and the Reference didn't describe the dispatch-time guarantee.
This commit is contained in:
parent
71cffcffdf
commit
42b8163f8f
|
@ -8,16 +8,16 @@ The @racket[case] form dispatches to a clause by matching the result
|
||||||
of an expression to the values for the clause:
|
of an expression to the values for the clause:
|
||||||
|
|
||||||
@specform[(case expr
|
@specform[(case expr
|
||||||
[(datum ...+) expr ...+]
|
[(datum ...+) body ...+]
|
||||||
...)]
|
...)]
|
||||||
|
|
||||||
Each @racket[_datum] will be compared to the result of the first
|
Each @racket[_datum] will be compared to the result of @racket[_expr]
|
||||||
@racket[_expr] using @racket[eqv?]. Since @racket[eqv?] doesn't work on
|
using @racket[equal?], and then the corresponding @racket[body]s are
|
||||||
many kinds of values, notably strings and lists, each @racket[_datum]
|
evaluated. The @racket[case] form can dispatch to the correct clause
|
||||||
is typically a number, symbol, or boolean.
|
in @math{O(log N)} time for @math{N} @racket[datum]s.
|
||||||
|
|
||||||
Multiple @racket[_datum]s can be supplied for each clause, and the
|
Multiple @racket[_datum]s can be supplied for each clause, and the
|
||||||
corresponding @racket[_expr] is evaluated if any of the
|
corresponding @racket[_body]s are evaluated if any of the
|
||||||
@racket[_datum]s match.
|
@racket[_datum]s match.
|
||||||
|
|
||||||
@examples[
|
@examples[
|
||||||
|
@ -41,5 +41,6 @@ like @racket[cond]:
|
||||||
[else 'many])
|
[else 'many])
|
||||||
]
|
]
|
||||||
|
|
||||||
For more general pattern matching, use @racket[match], which is
|
For more general pattern matching (but without the dispatch-time
|
||||||
introduced in @secref["match"].
|
guarantee), use @racket[match], which is introduced in
|
||||||
|
@secref["match"].
|
||||||
|
|
|
@ -99,13 +99,13 @@ as follows:
|
||||||
|
|
||||||
@refalso["if"]{@racket[cond]}
|
@refalso["if"]{@racket[cond]}
|
||||||
|
|
||||||
@specform[(cond [test-expr expr ...+]
|
@specform[(cond [test-expr body ...+]
|
||||||
...)]
|
...)]
|
||||||
|
|
||||||
Each @racket[_test-expr] is evaluated in order. If it produces
|
Each @racket[_test-expr] is evaluated in order. If it produces
|
||||||
@racket[#f], the corresponding @racket[_expr]s are ignored, and
|
@racket[#f], the corresponding @racket[_body]s are ignored, and
|
||||||
evaluation proceeds to the next @racket[_test-expr]. As soon as a
|
evaluation proceeds to the next @racket[_test-expr]. As soon as a
|
||||||
@racket[_test-expr] produces a true value, its @racket[_expr]s
|
@racket[_test-expr] produces a true value, its @racket[_body]s
|
||||||
are evaluated to produce the result for the @racket[cond] form, and no
|
are evaluated to produce the result for the @racket[cond] form, and no
|
||||||
further @racket[_test-expr]s are evaluated.
|
further @racket[_test-expr]s are evaluated.
|
||||||
|
|
||||||
|
@ -142,8 +142,8 @@ The full syntax of @racket[cond] includes two more kinds of clauses:
|
||||||
|
|
||||||
@specform/subs[#:literals (else =>)
|
@specform/subs[#:literals (else =>)
|
||||||
(cond cond-clause ...)
|
(cond cond-clause ...)
|
||||||
([cond-clause [test-expr then-expr ...+]
|
([cond-clause [test-expr then-body ...+]
|
||||||
[else then-expr ...+]
|
[else then-body ...+]
|
||||||
[test-expr => proc-expr]
|
[test-expr => proc-expr]
|
||||||
[test-expr]])]
|
[test-expr]])]
|
||||||
|
|
||||||
|
|
|
@ -2153,6 +2153,9 @@ For the selected @racket[case-clause], the results of the last
|
||||||
A @racket[case-clause] that starts with @racket[else] must be the last
|
A @racket[case-clause] that starts with @racket[else] must be the last
|
||||||
@racket[case-clause].
|
@racket[case-clause].
|
||||||
|
|
||||||
|
The @racket[case] form can dispatch to a matching @racket[case-clause]
|
||||||
|
in @math{O(log N)} time for @math{N} @racket[datum]s.
|
||||||
|
|
||||||
@mz-examples[
|
@mz-examples[
|
||||||
(case (+ 7 5)
|
(case (+ 7 5)
|
||||||
[(1 2 3) 'small]
|
[(1 2 3) 'small]
|
||||||
|
|
|
@ -74,6 +74,7 @@ Addded define-logger
|
||||||
Changed -W, -L, PLTSTDERR, and PLTSYSLOG to support log
|
Changed -W, -L, PLTSTDERR, and PLTSYSLOG to support log
|
||||||
filters of the form "<level> <name>=<level> ..."
|
filters of the form "<level> <name>=<level> ..."
|
||||||
Changed log-error, etc., to support format mode
|
Changed log-error, etc., to support format mode
|
||||||
|
Changed case to dispatch in logarithmic time
|
||||||
Added racket/format, which is re-exported by racket
|
Added racket/format, which is re-exported by racket
|
||||||
Added #:break and #:final clauses to for forms
|
Added #:break and #:final clauses to for forms
|
||||||
Added exn:break:hang-up and exn:break:terminate, added
|
Added exn:break:hang-up and exn:break:terminate, added
|
||||||
|
|
Loading…
Reference in New Issue
Block a user