(define (make-alt-pred new-equal?) (lambda (a) (lambda (b) (new-equal? a b))))
(define alt-equal? (make-alt-pred new-equal?))
(match <...> ((a (? (alt-equal? a)) <rest of pattern>) <body>)
and one example:
(define-record-type <posn> (make-posn x y) posn? (x posn-x set-posn-x!) (y posn-y set-posn-y!))
(define posn-equal?
(make-alt-pred
(match-lambda* ((($ <posn> x y) ($ <posn> x y)) #t) (_ #f))))
(define slope-equal?
(make-alt-pred
(match-lambda* ((($ <posn> x y) ($ <posn> w z))
(cond
((and (= 0 y) (= 0 z)) #t)
((or (= 0 y) (= 0 z)) #f)
(else (= (/ x y) (/ w z))))) (_ #f))))
(define (cross-peephole vec-product)
(match vec-product
(('cross a (? (posn-equal? a))) (make-posn 0 0))
(('cross a (? (slope-equal? a))) (make-posn 0 0))
(other other)))
I could make the make-alt-pred procedure part of the library if that seems like a good idea. I'm open to alternate names.