-
-
Notifications
You must be signed in to change notification settings - Fork 97
Automated Resyntax fixes #696
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
Conversation
This is an automated change generated by Resyntax. #### Pass 1 Applied 1 fix to [`drracket/drracket/private/in-irl-namespace.rkt`](../blob/HEAD/drracket/drracket/private/in-irl-namespace.rkt) * Line 256, `tidy-require`: Keep imports in `require` sorted and grouped by phase, with collections before files. Applied 12 fixes to [`drracket/drracket/private/tools.rkt`](../blob/HEAD/drracket/drracket/private/tools.rkt) * Line 3, `tidy-require`: Keep imports in `require` sorted and grouped by phase, with collections before files. * Line 112, `let-to-define`: Internal definitions are recommended instead of `let` expressions, to reduce nesting. * Line 169, `define-let-to-double-define`: This `let` expression can be pulled up into a `define` expression. * Line 192, `let-to-define`: Internal definitions are recommended instead of `let` expressions, to reduce nesting. * Line 239, `let-to-define`: Internal definitions are recommended instead of `let` expressions, to reduce nesting. * Line 386, `let-to-define`: Internal definitions are recommended instead of `let` expressions, to reduce nesting. * Line 434, `let-to-define`: Internal definitions are recommended instead of `let` expressions, to reduce nesting. * Line 532, `for-each-to-for`: This `for-each` operation can be replaced with a `for` loop. * Line 542, `let-to-define`: Internal definitions are recommended instead of `let` expressions, to reduce nesting. * Line 552, `let-to-define`: Internal definitions are recommended instead of `let` expressions, to reduce nesting. * Line 577, `let-to-define`: Internal definitions are recommended instead of `let` expressions, to reduce nesting. * Line 592, `let-to-define`: Internal definitions are recommended instead of `let` expressions, to reduce nesting. Applied 1 fix to [`drracket/drracket/private/module-browser.rkt`](../blob/HEAD/drracket/drracket/private/module-browser.rkt) * Line 3, `tidy-require`: Keep imports in `require` sorted and grouped by phase, with collections before files. #### Pass 2 Applied 2 fixes to [`drracket/drracket/private/tools.rkt`](../blob/HEAD/drracket/drracket/private/tools.rkt) * Line 131, `cond-let-to-cond-define`: Internal definitions are recommended instead of `let` expressions, to reduce nesting. * Line 445, `map-to-for`: This `map` operation can be replaced with a `for/list` loop. ## Summary Fixed 16 issues in 3 files. * Fixed 9 occurrences of `let-to-define` * Fixed 3 occurrences of `tidy-require` * Fixed 1 occurrence of `define-let-to-double-define` * Fixed 1 occurrence of `for-each-to-for` * Fixed 1 occurrence of `cond-let-to-cond-define` * Fixed 1 occurrence of `map-to-for`
drracket/drracket/private/tools.rkt
Outdated
| (set! tool-bitmap-x tool-bitmap-gap)) | ||
| (when ((+ tool-bitmap-y tool-bitmap-gap tool-bitmap-size) . > . splash-width) | ||
| (set! tool-bitmap-y tool-bitmap-gap))))))) | ||
| (make-object bitmap-dc%) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like (make-object bitmap-dc%) should just go away.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Not sure how to detect this statically though, since in general constructors can have side effects (and probably occasionally do in practice).
| (string<? (car a) (car b)))))) | ||
| (for ([entry+it (in-list (sort (map (lambda (it) (cons (tool-list-entry it) it)) | ||
| installed-tools) | ||
| (lambda (a b) (string<? (car a) (car b)))))]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be different; possibly not in the purview of these changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. I don't know of a good way to make this code much better, since sort needs to transform the whole list. That sort expression can be made a little simpler though since instead of passing that lambda it could pass (sort ... string<? #:key car). I already have a rule for that - I'm assuming it didn't fire here because the change hit the fix limit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an aside, that code is much easier to write with transducers:
(transduce installed-tools
(indexing tool-list-entry)
(sorting string<=> #:key entry-key)
#:into
(into-for-each
(lambda (entry+it)
(send listing append (car entry+it) (cdr entry+it)))))There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I just meant the simple change using sort's #:key argument. Sorry for being so opaque! Glad to hear that it'll get fixed on its own eventually! :)
The transducer code doesn't look much easier to me, but probably I'm missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh gotcha, yeah there's a rule for that sort fix. I thought you were talking about how indented the whole sort expression got because of it being on the right-hand-side of a for clause.
For the transducer code, I ought to have been clearer. The code I gave is equivalent to the whole for-each expression and for loop. These three snippets are all equivalent:
(for-each
(lambda (entry+it)
(send listing append
(car entry+it)
(cdr entry+it)))
(sort (map (lambda (it) (cons (tool-list-entry it) it))
installed-tools)
(lambda (a b)
(string<? (car a) (car b)))))(for ([entry+it (in-list (sort (map (lambda (it) (cons (tool-list-entry it) it))
installed-tools)
(lambda (a b) (string<? (car a) (car b)))))])
(send listing append (car entry+it) (cdr entry+it)))(transduce installed-tools
(indexing tool-list-entry)
(sorting string<=> #:key entry-key)
#:into
(into-for-each
(lambda (entry+it)
(send listing append (car entry+it) (cdr entry+it)))))It's pretty subjective (which I did not make clear in my previous comment) but I find the transducer version much easier to read assuming you know how to use transduce, since it's just a top-to-bottom series of steps applied to the initial list. Whenever I need to sort data and also do some transformation before or after, I usually use transducers because it's pretty hard to work sort into a for loop nicely. Plus sort is frustrating to use on non-lists.
|
Overall, looks good to me. Maybe I should make the changes I've suggested after this is merged? How does one best handle that sort of thing, where there are followup fixes that get noticed just by reading the diffs? |
|
@rfindler Making them after merging is totally reasonable. Alternatively, if you want to make them before approval you can check out this branch and push them immediately. |
|
I tried to push and it seemed to do something, but not quite right. How do you do this kind of thing? |
|
I think you have to push to the |
This is an automated change generated by Resyntax.
Pass 1
Applied 1 fix to
drracket/drracket/private/in-irl-namespace.rkttidy-require: Keep imports inrequiresorted and grouped by phase, with collections before files.Applied 12 fixes to
drracket/drracket/private/tools.rkttidy-require: Keep imports inrequiresorted and grouped by phase, with collections before files.let-to-define: Internal definitions are recommended instead ofletexpressions, to reduce nesting.define-let-to-double-define: Thisletexpression can be pulled up into adefineexpression.let-to-define: Internal definitions are recommended instead ofletexpressions, to reduce nesting.let-to-define: Internal definitions are recommended instead ofletexpressions, to reduce nesting.let-to-define: Internal definitions are recommended instead ofletexpressions, to reduce nesting.let-to-define: Internal definitions are recommended instead ofletexpressions, to reduce nesting.for-each-to-for: Thisfor-eachoperation can be replaced with aforloop.let-to-define: Internal definitions are recommended instead ofletexpressions, to reduce nesting.let-to-define: Internal definitions are recommended instead ofletexpressions, to reduce nesting.let-to-define: Internal definitions are recommended instead ofletexpressions, to reduce nesting.let-to-define: Internal definitions are recommended instead ofletexpressions, to reduce nesting.Applied 1 fix to
drracket/drracket/private/module-browser.rkttidy-require: Keep imports inrequiresorted and grouped by phase, with collections before files.Pass 2
Applied 2 fixes to
drracket/drracket/private/tools.rktcond-let-to-cond-define: Internal definitions are recommended instead ofletexpressions, to reduce nesting.map-to-for: Thismapoperation can be replaced with afor/listloop.Summary
Fixed 16 issues in 3 files.
let-to-definetidy-requiredefine-let-to-double-definefor-each-to-forcond-let-to-cond-definemap-to-for