case-clause = [(datum ...) then-body ...+] | [else then-body ...+](case val-expr case-clause ...)
Evaluates
val-exprand uses the result to select a
case-clause. The selected clause is the first one with a
datumwhose
quoted form is
equal?to the result of
val-expr. If no such
datumis present, the
else case-clauseis selected; if no
else case-clauseis present, either, then the result of the
caseform is
#<void>.
The case form of racket differs from that of R6RS or R5RS by being based on equal? instead of eqv? (in addition to allowing internal definitions).
For the selected case-clause, the results of the last then-body, which is in tail position with respect to the case form, are the results for the whole case form.
A case-clause that starts with else must be the last case-clause.
The case form can dispatch to a matching case-clause in O(log N) time for N datums.
Examples:
> (case (+ 7 5) [(1 2 3) 'small] [(10 11 12) 'big])3.13.1 Variants of case🔗ℹ'big
> (case (- 7 5) [(1 2 3) 'small] [(10 11 12) 'big])'small
"animal"
> (case (list 'y 'x) [((a b) (x y)) 'forwards] [((b a) (y x)) 'backwards])'backwards
> (case 'x [(x) "ex"] [('x) "quoted ex"])"ex"
> (case (list 'quote 'x) [(x) "ex"] [('x) "quoted ex"])"quoted ex"
> (classify #\A)"letter"
> (classify #\1)"number"
> (classify #\!)"other"
Added in version 8.11.1.8 of package base.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4