Move ==' to racket/match'.

This commit is contained in:
Sam Tobin-Hochstadt 2011-11-13 22:09:49 -05:00
parent 5fe89966fc
commit 81dd112f57
5 changed files with 31 additions and 32 deletions

View File

@ -13,7 +13,7 @@
(provide (for-syntax match-...-nesting)
match-equality-test
define-match-expander
struct*
struct* ==
exn:misc:match?)
(define-forms parse

View File

@ -70,4 +70,12 @@
(quasisyntax/loc stx
(struct struct-name #,pats-in-order))))])))
(provide struct*)
(provide struct* ==)
(define-match-expander
==
(lambda (stx)
(syntax-case stx ()
[(_ val comp)
#'(? (lambda (x) (comp val x)))]
[(_ val) #'(? (lambda (x) (equal? val x)))])))

View File

@ -544,6 +544,26 @@ instead of @racket[match].}
@section{Library Extensions}
@defform*[[(== val comparator) (== val)]]{
A @tech{match expander}
which checks if the matched value is the same as @racket[val] when
compared by @racket[comparator]. If @racket[comparator] is
not provided, it defaults to @racket[equal?].
@examples[#:eval match-eval
(match (list 1 2 3)
[(== (list 1 2 3)) 'yes]
[_ 'no])
(match (list 1 2 3)
[(== (list 1 2 3) eq?) 'yes]
[_ 'no])
(match (list 1 2 3)
[(list 1 2 (== 3 =)) 'yes]
[_ 'no])
]
}
@defform[(struct* struct-id ([field pat] ...))]{
A @racket[match] pattern form that matches an instance of a structure
type named @racket[struct-id], where the field @racket[field] in the

View File

@ -5,15 +5,7 @@
(for-syntax racket/base)
(for-syntax syntax/parse))
(provide == match? as object)
(define-match-expander
==
(lambda (stx)
(syntax-case stx ()
[(_ val comp)
#'(? (lambda (x) (comp val x)))]
[(_ val) #'(== val equal?)])))
(provide match? as object)
(define-syntax-rule (match? e p ...)
(match e [p #t] ... [_ #f]))

View File

@ -9,27 +9,6 @@
@defmodule[unstable/match]
@unstable[@author+email["Sam Tobin-Hochstadt" "samth@ccs.neu.edu"]]
@defform*[[(== val comparator) (== val)]]{
A @tech[#:doc '(lib "scribblings/reference/reference.scrbl")]{match expander}
which checks if the matched value is the same as @racket[val] when
compared by @racket[comparator]. If @racket[comparator] is
not provided, it defaults to @racket[equal?].
@examples[#:eval the-eval
(match (list 1 2 3)
[(== (list 1 2 3)) 'yes]
[_ 'no])
(match (list 1 2 3)
[(== (list 1 2 3) eq?) 'yes]
[_ 'no])
(match (list 1 2 3)
[(list 1 2 (== 3 =)) 'yes]
[_ 'no])
]
}
@addition[@author+email["Carl Eastlund" "cce@racket-lang.org"]]
@defform[(match? val-expr pat ...)]{