Skip to content

Automated Resyntax fixes #1438

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

Closed
wants to merge 18 commits into from
Closed

Automated Resyntax fixes #1438

wants to merge 18 commits into from

Conversation

resyntax-ci[bot]
Copy link
Contributor

@resyntax-ci resyntax-ci bot commented Feb 28, 2025

Resyntax fixed 41 issues in 20 files.

  • Fixed 15 occurrences of single-clause-match-to-match-define
  • Fixed 6 occurrences of let-to-define
  • Fixed 2 occurrences of define-simple-macro-to-define-syntax-parse-rule
  • Fixed 2 occurrences of if-else-false-to-and
  • Fixed 2 occurrences of zero-comparison-to-positive?
  • Fixed 2 occurrences of map-to-for
  • Fixed 2 occurrences of sort-with-keyed-comparator-to-sort-by-key
  • Fixed 1 occurrence of case-lambda-with-single-case-to-lambda
  • Fixed 1 occurrence of if-begin-to-cond
  • Fixed 1 occurrence of define-lambda-to-define
  • Fixed 1 occurrence of inverted-unless
  • Fixed 1 occurrence of provide-deduplication
  • Fixed 1 occurrence of begin0-let-to-define-begin0
  • Fixed 1 occurrence of inverted-when
  • Fixed 1 occurrence of define-values-values-to-define
  • Fixed 1 occurrence of cond-let-to-cond-define
  • Fixed 1 occurrence of syntax-disarm-migration

resyntax-ci bot added 18 commits February 28, 2025 00:35
The `define-simple-macro` form has been renamed to `define-syntax-parse-rule`.
This expression is equivalent to calling the `positive?` predicate.
The `syntax-disarm` function is a legacy function that does nothing.
Internal definitions are recommended instead of `let` expressions, to reduce nesting.
This `if` expression can be refactored to an equivalent expression using `and`.
This `match` expression can be simplified using `match-define`.
This `map` operation can be replaced with a `for/list` loop.
The `define` form supports a shorthand for defining functions.
Providing the same identifier multiple times is unnecessary.
Using `cond` instead of `if` here makes `begin` unnecessary
The `let` expression in this `begin0` form can be extracted into the surrounding definition context.
This `case-lambda` form only has one case. Use a regular lambda instead.
This use of `define-values` is unnecessary.
This negated `unless` expression can be replaced by a `when` expression.
This `sort` expression can be replaced with a simpler, equivalent expression.
This negated `when` expression can be replaced by an `unless` expression.
Internal definitions are recommended instead of `let` expressions, to reduce nesting.
Internal definitions are recommended instead of `let` expressions, to reduce nesting.
(raise-arguments-error
(string->symbol (format "typed/racket/~a" (keyword->string (syntax-e te-attr))))
Copy link
Member

Choose a reason for hiding this comment

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

@jackfirth this could use format-symbol from racket/syntax

Copy link
Contributor

Choose a reason for hiding this comment

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

Added a new rule for this in jackfirth/resyntax#442.

@@ -143,8 +143,7 @@
[#:for-each (f) (for-each f ps)]
[#:custom-constructor/contract
(-> (listof (or/c TypeProp? NotTypeProp? LeqProp?)) OrProp?)
(let ([ps (sort ps (λ (p q) (unsafe-fx<= (eq-hash-code p)
Copy link
Member

Choose a reason for hiding this comment

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

@jackfirth my guess is that this change is slower

Copy link
Contributor

Choose a reason for hiding this comment

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

If it is, that seems like a missed optimization opportunity in sort.

Copy link
Member

Choose a reason for hiding this comment

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

It's really an issue of inlining.

(map f* vals)
(and call-cc (map f* call-cc)))]))
(match-define (pt-seq vals call-cc) seq)
(define (f* a)
Copy link
Member

Choose a reason for hiding this comment

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

@sorawee why is this on two lines?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's a "community"'s preference to always format function definition this way. It used to support one-line format, but IIRC, either @jackfirth or @Metaxal gathered supporters to NOT do the one-line format, and I made the change accordingly.

Copy link
Member

Choose a reason for hiding this comment

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

I would be interested to find that discussion; I strongly disagree.

Copy link

Choose a reason for hiding this comment

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

If it was me, I don't remember having a strong opinion about this. Perhaps it was more of a pragmatic choice at that time(?). But again, perhaps it wasn't me 😁

Copy link
Contributor

Choose a reason for hiding this comment

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

It's @Metaxal. I'm very lucky that I wrote your name in the commit message 😂

sorawee/fmt@831bb4c

Copy link

Choose a reason for hiding this comment

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

Haha indeed! Though "Suggestion by" sounds a bit different from "gathered supporters to NOT do" ;)

Again, I don't feel particularly strongly about this, although I do have a preference for two lines so that the function header stands out. I'm not going to die on this hill though.

Copy link
Contributor

Choose a reason for hiding this comment

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

It was also me. I was (and still am) of the strong opinion that function definitions should never be on a single line. Otherwise it's hard to tell them apart from variable definitions.

Copy link
Member

Choose a reason for hiding this comment

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

Functions are just another kind of variable. ;)

(let-values ([(l c p) (port-next-location port)])
(raise-read-error (format "typed expression ~a not properly terminated"
(syntax->datum name))
src
Copy link
Member

Choose a reason for hiding this comment

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

I hate this indentation.

Copy link
Contributor

Choose a reason for hiding this comment

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

What's your preferred format?

Copy link
Member

Choose a reason for hiding this comment

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

having all the additional arguments on the same line. I realize that this preference of mine is not widely shared but I'm still grumpy.

Copy link

Choose a reason for hiding this comment

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

FWIW, I also find the new indentation jarring: there's a big empty space with just a few letters. It's quite wasteful information-wise.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with this particular case, but I'm not sure how to turn this into code in a way that makes other cases also look good.

E.g.: compare:

(format "This is a very long string"
        first-long-string second-long-string third-long-string fourth-long-string))

vs:

(format "This is a very long string"
        first-long-string 
        second-long-string 
        third-long-string 
        fourth-long-string))

I think the second one is preferable.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I agree with that. I bet you can make resyntax do it though. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I could attempt something. Do you think this case with raise-read-error comes up enough to be worth it?

Copy link
Member

Choose a reason for hiding this comment

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

No it would have to be more general, but I bet the case where format is involved happens a lot.

Copy link
Contributor

Choose a reason for hiding this comment

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

More general is trickier because it makes it difficult to pick a good name for the introduced variable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good excuse to use LLM to find a name?

@samth
Copy link
Member

samth commented Apr 18, 2025

Should this be merged or closed?

@jackfirth
Copy link
Contributor

@samth Up to you. Resyntax cannot (yet) update pull requests after it's made them so the options are to merge it as-is, merge it with manual edits for anything you want to change, or close it and let Resyntax try again next time. As the repo owner I defer to you on that choice.

@samth
Copy link
Member

samth commented Apr 18, 2025

Ok I'm going to close this and we'll see what the next one does.

@samth samth closed this Apr 18, 2025
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.

4 participants