Add null-when-guard-to-match-pattern rule#839
Open
jackfirth wants to merge 1 commit into
Open
Conversation
Fold a `#:when (null? xs)` / `#:when (empty? xs)` guard on a match clause whose pattern ends in a trailing ellipsis variable `xs ...` directly into the pattern by dropping the variable, turning e.g. `[(list 'array elems ...) #:when (null? elems) body]` into `[(list 'array) body]`. Only applies when the trailing variable isn't used in the clause body. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
|
Docs preview: https://resyntax.notjack.space/preview/839/ |
Contributor
There was a problem hiding this comment.
Resyntax analyzed 2 files in this pull request and found no issues.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a rule that folds a
#:when (null? xs)(orempty?) guard into thematchpattern when the clause's pattern ends in a trailing ellipsis variablexs ...that the body doesn't use. So this:becomes:
This came up in an Autofixer PR against Herbie (herbie-fp/herbie#1626, https://github.com/herbie-fp/herbie/blob/25413a2279729497b92c7d35390be595e0a4fd8c/src/syntax/platform-language.rkt#L44-L52).
match-conditional-to-whenhad already lifted a(if (null? elems) #f ...)body into a#:whenguard plus a fallthrough clause, but nothing then noticed the guard could be expressed by the pattern itself. Since Resyntax runs rules to a fixpoint, this new rule composes withmatch-conditional-to-whenso future runs land on the fully simplified form.🤖 Generated with Claude Code