Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace conditionals in match with #:when #389

Open
jackfirth opened this issue Nov 8, 2024 · 0 comments
Open

Replace conditionals in match with #:when #389

jackfirth opened this issue Nov 8, 2024 · 0 comments
Labels
new lint Issues suggesting new lints or pull requests implementing new lints

Comments

@jackfirth
Copy link
Owner

Saw a few cases in racket/typed-racket#1410 where #:when would clean up various bits of pattern matching code:

#lang resyntax/test

test: "original code should be refactorable to new code"
--------------------
#lang racket
(define (f pt)
  (match pt
    [(list x y)
     (if (> x y)
         (list y x)
         pt)]
    [(list) '()]))
--------------------
--------------------
#lang racket
(define (f pt)
  (match pt
    [(list x y)
     #:when (> x y)
     (list y x)]
    [(list x y) pt]
    [(list) '()]))
--------------------

This should probably only trigger when the pattern is small. It should also only trigger on match expressions that already have multiple branches, since the single-branch case would be clearer as a match-define. A two-case cond instead of an if should also count.

@jackfirth jackfirth added the new lint Issues suggesting new lints or pull requests implementing new lints label Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new lint Issues suggesting new lints or pull requests implementing new lints
Projects
None yet
Development

No branches or pull requests

1 participant