Add unstable/match with == match expander.
Add 'match expander' tech def. svn: r16814
This commit is contained in:
parent
4f5479e912
commit
0ae5843f11
|
@ -423,7 +423,7 @@ A predicate for the exception raised by in the case of a match failure.
|
||||||
@defform*[((define-match-expander id proc-expr)
|
@defform*[((define-match-expander id proc-expr)
|
||||||
(define-match-expander id proc-expr proc-expr))]{
|
(define-match-expander id proc-expr proc-expr))]{
|
||||||
|
|
||||||
Binds @scheme[id] to a pattern transformer.
|
Binds @scheme[id] to a @deftech{match expander}.
|
||||||
|
|
||||||
The first @scheme[proc-expr] subexpression must evaluate to a
|
The first @scheme[proc-expr] subexpression must evaluate to a
|
||||||
transformer that produces a @scheme[_pat] for @scheme[match].
|
transformer that produces a @scheme[_pat] for @scheme[match].
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
(require "../utils/utils.ss")
|
(require "../utils/utils.ss")
|
||||||
|
|
||||||
(require mzlib/struct
|
(require mzlib/struct
|
||||||
mzlib/plt-match
|
scheme/match
|
||||||
syntax/boundmap
|
syntax/boundmap
|
||||||
"free-variance.ss"
|
"free-variance.ss"
|
||||||
"interning.ss"
|
"interning.ss"
|
||||||
unstable/syntax
|
unstable/syntax unstable/match
|
||||||
mzlib/etc
|
mzlib/etc
|
||||||
scheme/contract
|
scheme/contract
|
||||||
(for-syntax
|
(for-syntax
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
[i:boolean (-val (syntax-e #'i))]
|
[i:boolean (-val (syntax-e #'i))]
|
||||||
[i:identifier (-val (syntax-e #'i))]
|
[i:identifier (-val (syntax-e #'i))]
|
||||||
[i:exact-integer -Integer]
|
[i:exact-integer -Integer]
|
||||||
[i:number -Number]
|
[(~var i (3d real?)) -Number]
|
||||||
[i:str -String]
|
[i:str -String]
|
||||||
[i:char -Char]
|
[i:char -Char]
|
||||||
[i:keyword (-val (syntax-e #'i))]
|
[i:keyword (-val (syntax-e #'i))]
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
[->* -->*]
|
[->* -->*]
|
||||||
[one-of/c -one-of/c])
|
[one-of/c -one-of/c])
|
||||||
(rep type-rep)
|
(rep type-rep)
|
||||||
scheme/contract scheme/match
|
scheme/contract scheme/match unstable/match
|
||||||
(for-syntax scheme/base))
|
(for-syntax scheme/base))
|
||||||
|
|
||||||
(provide combine-filter apply-filter abstract-filter abstract-filters
|
(provide combine-filter apply-filter abstract-filter abstract-filters
|
||||||
|
|
|
@ -11,7 +11,7 @@ at least theoretically.
|
||||||
scheme/pretty mzlib/pconvert syntax/parse)
|
scheme/pretty mzlib/pconvert syntax/parse)
|
||||||
|
|
||||||
;; to move to unstable
|
;; to move to unstable
|
||||||
(provide == debug reverse-begin)
|
(provide debug reverse-begin)
|
||||||
|
|
||||||
(provide
|
(provide
|
||||||
;; timing
|
;; timing
|
||||||
|
@ -140,14 +140,6 @@ at least theoretically.
|
||||||
(printf "Timing ~a at ~a@~a~n" msg diff t)))]))
|
(printf "Timing ~a at ~a@~a~n" msg diff t)))]))
|
||||||
(values (lambda _ #'(void)) (lambda _ #'(void)))))
|
(values (lambda _ #'(void)) (lambda _ #'(void)))))
|
||||||
|
|
||||||
|
|
||||||
(define-match-expander
|
|
||||||
==
|
|
||||||
(lambda (stx)
|
|
||||||
(syntax-case stx ()
|
|
||||||
[(_ val)
|
|
||||||
#'(? (lambda (x) (equal? val x)))])))
|
|
||||||
|
|
||||||
;; custom printing
|
;; custom printing
|
||||||
;; this requires lots of work for two reasons:
|
;; this requires lots of work for two reasons:
|
||||||
;; - 1 printers have to be defined at the same time as the structs
|
;; - 1 printers have to be defined at the same time as the structs
|
||||||
|
|
13
collects/unstable/match.ss
Normal file
13
collects/unstable/match.ss
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#lang scheme/base
|
||||||
|
|
||||||
|
(require scheme/match (for-syntax scheme/base))
|
||||||
|
|
||||||
|
(provide ==)
|
||||||
|
|
||||||
|
(define-match-expander
|
||||||
|
==
|
||||||
|
(lambda (stx)
|
||||||
|
(syntax-case stx ()
|
||||||
|
[(_ val comp)
|
||||||
|
#'(? (lambda (x) (comp val x)))]
|
||||||
|
[(_ val) #'(== val equal?)])))
|
37
collects/unstable/scribblings/match.scrbl
Normal file
37
collects/unstable/scribblings/match.scrbl
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
#lang scribble/doc
|
||||||
|
@(require scribble/base
|
||||||
|
scribble/manual
|
||||||
|
scribble/eval
|
||||||
|
"utils.ss"
|
||||||
|
(for-label unstable/match
|
||||||
|
scheme/match
|
||||||
|
scheme/contract
|
||||||
|
scheme/base))
|
||||||
|
|
||||||
|
@(define the-eval (make-base-eval))
|
||||||
|
@(the-eval '(require unstable/match scheme/match))
|
||||||
|
|
||||||
|
@title[#:tag "match"]{Match}
|
||||||
|
|
||||||
|
@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 @scheme[val] when
|
||||||
|
compared by @scheme[comparator]. If @scheme[comparator] is
|
||||||
|
not provided, it defaults to @scheme[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])
|
||||||
|
]
|
||||||
|
}
|
|
@ -86,6 +86,7 @@ Keep documentation and tests up to date.
|
||||||
@include-section["class-iop.scrbl"]
|
@include-section["class-iop.scrbl"]
|
||||||
@include-section["sequence.scrbl"]
|
@include-section["sequence.scrbl"]
|
||||||
@include-section["hash.scrbl"]
|
@include-section["hash.scrbl"]
|
||||||
|
@include-section["match.scrbl"]
|
||||||
|
|
||||||
@;{--------}
|
@;{--------}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user