-
-
Notifications
You must be signed in to change notification settings - Fork 97
Automated Resyntax fixes #790
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
| (define win-label (and (is-a? window window<%>) (send window get-label))) | ||
| (equal? label win-label)] | ||
| [else #f]) | ||
| (list window)] |
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 doesn't seem ideal.
Internal definitions are recommended instead of `let` expressions, to reduce nesting.
This `map` operation can be replaced with a `for/list` loop.
Internal definitions are recommended instead of `let` expressions, to reduce nesting.
Use the `#:when` keyword instead of `when` to reduce loop body indentation.
Nested `when` expressions can be merged into a single compound `when` expression.
The `instantiate` form is for mixing positional and by-name constructor arguments. When no positional arguments are needed, use `new` instead.
This named `let` expression is equivalent to a `for` loop that uses `in-range`.
Use the `#:unless` keyword instead of `unless` to reduce loop body indentation.
fbfb661 to
194e2da
Compare
|
I removed the (IMO) questionable commit. |
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.
Resyntax analyzed 7 files in this pull request and has added suggestions.
| (let loop ([dy (- (/ quadrant-size 2))]) | ||
| (when (< dy h) | ||
| (send dc set-alpha 1) | ||
| (send dc set-brush palaka-color 'solid) | ||
| (send dc draw-rectangle dx dy quadrant-size quadrant-size) | ||
| (send dc set-brush "white" 'solid) | ||
| (draw-one-palaka dc dx dy) | ||
| (loop (+ dy quadrant-size))))) |
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.
named-let-loop-to-for-in-range: This named let expression is equivalent to a for loop that uses in-range.
| (let loop ([dy (- (/ quadrant-size 2))]) | |
| (when (< dy h) | |
| (send dc set-alpha 1) | |
| (send dc set-brush palaka-color 'solid) | |
| (send dc draw-rectangle dx dy quadrant-size quadrant-size) | |
| (send dc set-brush "white" 'solid) | |
| (draw-one-palaka dc dx dy) | |
| (loop (+ dy quadrant-size))))) | |
| (for ([dy (in-range (- (/ quadrant-size 2)) h quadrant-size)]) | |
| (send dc set-alpha 1) | |
| (send dc set-brush palaka-color 'solid) | |
| (send dc draw-rectangle dx dy quadrant-size quadrant-size) | |
| (send dc set-brush "white" 'solid) | |
| (draw-one-palaka dc dx dy))) |
Debugging details
Textual replacement
(line-replacement
#:new-lines
'#(" (for ([dy (in-range (- (/ quadrant-size 2)) h quadrant-size)])"
" (send dc set-alpha 1)"
" (send dc set-brush palaka-color 'solid)"
" (send dc draw-rectangle dx dy quadrant-size quadrant-size)"
" (send dc set-brush \"white\" 'solid)"
" (draw-one-palaka dc dx dy)))")
#:original-lines
'#(" (let loop ([dy (- (/ quadrant-size 2))])"
" (when (< dy h)"
" (send dc set-alpha 1)"
" (send dc set-brush palaka-color 'solid)"
" (send dc draw-rectangle dx dy quadrant-size quadrant-size)"
" (send dc set-brush \"white\" 'solid)"
" (draw-one-palaka dc dx dy)"
" (loop (+ dy quadrant-size)))))")
#:start-line 28)Syntactic replacement
(syntax-replacement
#:introduction-scope #<procedure:...and/syntax-local.rkt:148:2>
#:new-syntax
#<syntax:/home/runner/.local/share/racket/9.1.0.1/pkgs/resyntax/default-recommendations/loops/named-let-loopification.rkt:40:2 (for ((dy (in-range (- (/ quadrant-size 2)) h quadrant-size))) (send dc set-alpha 1) (send dc set-brush palaka-color (quote solid)) (send dc draw-rectangle dx dy quadrant-size quadrant-size) (send dc set-brush "white" (quote solid)) (draw-one-palaka dc ...>
#:original-syntax
#<syntax:drracket-core-lib/drracket/private/palaka.rkt:28:4 (let loop ((dy (- (/ quadrant-size 2)))) (when (< dy h) (send dc set-alpha 1) (send dc set-brush palaka-color (quote solid)) (send dc draw-rectangle dx dy quadrant-size quadrant-size) (send dc set-brush "white" (quote solid)) (draw-one-palaka dc dx dy) ...>
#:source
(file-source
#<path:/home/runner/work/drracket/drracket/drracket-core-lib/drracket/private/palaka.rkt>)
#:uses-universal-tagged-syntax? #f)| (if (<= counter 0) | ||
| (fail) | ||
| (let ([result (pred)]) | ||
| (or result | ||
| (begin | ||
| (sleep step) | ||
| (loop (- counter step)))))))) |
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.
if-let-to-cond: cond with internal definitions is preferred over if with let, to reduce nesting
| (if (<= counter 0) | |
| (fail) | |
| (let ([result (pred)]) | |
| (or result | |
| (begin | |
| (sleep step) | |
| (loop (- counter step)))))))) | |
| (cond | |
| [(<= counter 0) (fail)] | |
| [else | |
| (define result (pred)) | |
| (or result | |
| (begin | |
| (sleep step) | |
| (loop (- counter step))))]))) |
Debugging details
Textual replacement
(line-replacement
#:new-lines
'#(" (cond"
" [(<= counter 0) (fail)]"
" [else"
" (define result (pred))"
" (or result"
" (begin"
" (sleep step)"
" (loop (- counter step))))])))")
#:original-lines
'#(" (if (<= counter 0)"
" (fail)"
" (let ([result (pred)])"
" (or result"
" (begin"
" (sleep step)"
" (loop (- counter step))))))))")
#:start-line 127)Syntactic replacement
(syntax-replacement
#:introduction-scope #<procedure:...and/syntax-local.rkt:148:2>
#:new-syntax
#<syntax:/home/runner/.local/share/racket/9.1.0.1/pkgs/resyntax/default-recommendations/let-replacement/cond-let-replacement.rkt:47:2 (cond ((<= counter 0) (fail)) (else (define result (pred)) (or result (begin (sleep step) (loop (- counter step))))))>
#:original-syntax
#<syntax:drracket-test/tests/drracket/private/no-fw-test-util.rkt:127:4 (if (<= counter 0) (fail) (let ((result (pred))) (or result (begin (sleep step) (loop (- counter step))))))>
#:source
(file-source
#<path:/home/runner/work/drracket/drracket/drracket-test/tests/drracket/private/no-fw-test-util.rkt>)
#:uses-universal-tagged-syntax? #f)
Resyntax fixed 20 issues in 7 files.
unless-expression-in-for-loop-to-unless-keywordlet-to-definemap-to-forwhen-expression-in-for-loop-to-when-keywordand-let-to-condnamed-let-loop-to-for-in-rangenested-when-to-compound-whencond-let-to-cond-defineinstantiate-to-new