non-linearly, I think this would be:

(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.


On Sat, Sep 5, 2020 at 11:20 AM Marc Nieper-Wißkirchen <xxxxxx@nieper-wisskirchen.de> wrote:
When a pattern variable is repeated, the matcher compares the new with
the old value using equal?. This makes a lot of sense when all that is
matched are lists and vectors. In general, however, we can also match
records or use custom predicates (through the ? operator). In view of
this, unconditionally using equal? for repeated pattern variables is
arbitrary.

So what I am looking for is a way to associate with a (repeated)
pattern variable an equivalence predicate, which will then be used by
the matcher. So, in some sense, pattern variables need to be "typed"
for giving repeated pattern variables complete sense.