hack evcase to support old and new 'else' bindings

svn: r9481
This commit is contained in:
Matthew Flatt 2008-04-25 21:36:37 +00:00
parent f2a3317df6
commit 01baad11a0
3 changed files with 16 additions and 9 deletions

View File

@ -8,6 +8,7 @@
build-list build-list
build-vector build-vector
compose) compose)
(rename scheme/base base-else else)
"kw.ss") "kw.ss")
(require-for-syntax syntax/kerncase (require-for-syntax syntax/kerncase
@ -136,8 +137,9 @@
(let ([tests (syntax->list (syntax (test ...)))]) (let ([tests (syntax->list (syntax (test ...)))])
(with-syntax ([(a-test ...) (with-syntax ([(a-test ...)
(map (lambda (t) (map (lambda (t)
(syntax-case t (else) (syntax-case t (else base-else)
[else (syntax #t)] [else (syntax #t)]
[base-else (syntax #t)]
[_else (with-syntax ([t t]) [_else (with-syntax ([t t])
(syntax (eqv? evcase-v t)))])) (syntax (eqv? evcase-v t)))]))
tests)]) tests)])

View File

@ -12,11 +12,12 @@
@interaction-eval[#:eval etc-eval (require mzlib/etc)] @interaction-eval[#:eval etc-eval (require mzlib/etc)]
@(begin @(begin
(define-syntax-rule (bind id) (define-syntax-rule (bind id else-id)
(begin (begin
(require (for-label scheme/base)) (require (for-label scheme/base))
(define id (scheme lambda)))) (define id (scheme lambda))
(bind base-lambda)) (define else-id (scheme else))))
(bind base-lambda base-else))
@mzlib[#:mode title etc] @mzlib[#:mode title etc]
@ -108,7 +109,11 @@ data. After @scheme[key-expr] is evaluated, each @scheme[value-expr]
is evaluated until a value is found that is @scheme[eqv?] to the key is evaluated until a value is found that is @scheme[eqv?] to the key
value; when a matching value is found, the corresponding value; when a matching value is found, the corresponding
@scheme[body-expr]s are evaluated and the value(s) for the last is the @scheme[body-expr]s are evaluated and the value(s) for the last is the
result of the entire @scheme[evcase] expression.} result of the entire @scheme[evcase] expression.
The @scheme[else] literal is recognized either as unbound (like in the
@schememodname[mzscheme] language) or bound as @|base-else| from
@schememodname[scheme/base].}
@defproc[(identity [v any/c]) any/c]{ @defproc[(identity [v any/c]) any/c]{

View File

@ -44,10 +44,10 @@ In more detail, patterns match as follows:
@itemize{ @itemize{
@item{@scheme[_id], excluding the reserved names @schemeidfont{"_"}, @item{@scheme[_id], excluding the reserved names @schemeidfont{_},
@schemeidfont{"..."}, @schemeidfont{".._"}, @schemeidfont{...}, @schemeidfont{.._},
@schemeidfont{".."}@scheme[_k], and @schemeidfont{..}@scheme[_k], and
@schemeidfont{".."}@scheme[_k] for non-negative integers @schemeidfont{..}@scheme[_k] for non-negative integers
@scheme[_k] --- matches anything, and binds @scheme[id] to the @scheme[_k] --- matches anything, and binds @scheme[id] to the
matching values. If an @scheme[_id] is used multiple times matching values. If an @scheme[_id] is used multiple times
within a pattern, the corresponding matches must be the same within a pattern, the corresponding matches must be the same