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:
Matthew Flatt 2013-02-21 08:32:52 -07:00
parent 71cffcffdf
commit 42b8163f8f
4 changed files with 18 additions and 13 deletions

View File

@ -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:
@specform[(case expr
[(datum ...+) expr ...+]
[(datum ...+) body ...+]
...)]
Each @racket[_datum] will be compared to the result of the first
@racket[_expr] using @racket[eqv?]. Since @racket[eqv?] doesn't work on
many kinds of values, notably strings and lists, each @racket[_datum]
is typically a number, symbol, or boolean.
Each @racket[_datum] will be compared to the result of @racket[_expr]
using @racket[equal?], and then the corresponding @racket[body]s are
evaluated. The @racket[case] form can dispatch to the correct clause
in @math{O(log N)} time for @math{N} @racket[datum]s.
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.
@examples[
@ -41,5 +41,6 @@ like @racket[cond]:
[else 'many])
]
For more general pattern matching, use @racket[match], which is
introduced in @secref["match"].
For more general pattern matching (but without the dispatch-time
guarantee), use @racket[match], which is introduced in
@secref["match"].

View File

@ -99,13 +99,13 @@ as follows:
@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
@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
@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
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 =>)
(cond cond-clause ...)
([cond-clause [test-expr then-expr ...+]
[else then-expr ...+]
([cond-clause [test-expr then-body ...+]
[else then-body ...+]
[test-expr => proc-expr]
[test-expr]])]

View File

@ -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
@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[
(case (+ 7 5)
[(1 2 3) 'small]

View File

@ -74,6 +74,7 @@ Addded define-logger
Changed -W, -L, PLTSTDERR, and PLTSYSLOG to support log
filters of the form "<level> <name>=<level> ..."
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 #:break and #:final clauses to for forms
Added exn:break:hang-up and exn:break:terminate, added