jackfirth / resyntax

A Racket refactoring engine
Apache License 2.0
56 stars 10 forks source link

Suggest replacing `match` with `match-define` when reasonable #141

Closed jackfirth closed 2 years ago

jackfirth commented 3 years ago

This code:

(define (point-radius p)
  (match p
    [(point x y)
     (sqrt (+ (sqr x) (sqr y)))]))

can be better written with match-define instead, like this:

(define (point-radius p)
  (match-define (point x y) p)
  (sqrt (+ (sqr x) (sqr y))))

Resyntax ought to suggest this. The logic is similar to let-to-define, with the added condition that it should only happen for (tail-position) match expressions that have a single clause.