|(require colon-match)||package: colon-match|
For example the pattern x:num is equivalent to the pattern (? number? x).
A pattern of the form id:type is rewritten to (type id), and then type is is a match expander that expands to something like (? type? id). This means that you can define your own ":match classes" by defining them as match expanders.
> (require colon-match racket/match racket/contract/base (for-syntax racket/base)) > (match '(1 2 3) [(:pat (list a:num b:num c:num)) (+ a b c)])
> (match '(1 2 3) [(list (:pat a:num) _ _) a])
> (define-match-expander pos-num (syntax-rules () [(pos-num id) (? (and/c number? positive?) id)])) > (match 1 [(:pat x:pos-num) x])
> (match -1 [(:pat x:pos-num) x] [_ #f])
> (:match 1 [x:pos-num x])
(define-:match-class id pred-expr)