Skip to content

Add null-when-guard-to-match-pattern rule#839

Open
jackfirth wants to merge 1 commit into
masterfrom
null-when-guard-to-match-pattern
Open

Add null-when-guard-to-match-pattern rule#839
jackfirth wants to merge 1 commit into
masterfrom
null-when-guard-to-match-pattern

Conversation

@jackfirth

Copy link
Copy Markdown
Owner

Adds a rule that folds a #:when (null? xs) (or empty?) guard into the match pattern when the clause's pattern ends in a trailing ellipsis variable xs ... that the body doesn't use. So this:

[(list 'array elems ...)
 #:when (null? elems)
 #f]

becomes:

[(list 'array) #f]

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-when had already lifted a (if (null? elems) #f ...) body into a #:when guard 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 with match-conditional-to-when so future runs land on the fully simplified form.

🤖 Generated with Claude Code

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>
@github-actions

Copy link
Copy Markdown
Contributor

Docs preview: https://resyntax.notjack.space/preview/839/

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resyntax analyzed 2 files in this pull request and found no issues.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage is 96.611%null-when-guard-to-match-pattern into master. No base build found for master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants