Automated Resyntax fixes#814
Conversation
These list element variable definitions can be expressed more succinctly with `match-define`. Note that the suggested replacement raises an error if the list contains more elements than expected.
Using `cond` allows converting `let` to internal definitions, reducing nesting
This use of `printf` has no arguments other than the template string.
Internal definitions are recommended instead of `let` expressions, to reduce nesting.
This expression can be replaced with a simpler, equivalent `hash-update!` expression.
Use the `#:when` keyword instead of `when` to reduce loop body indentation.
Internal definitions are recommended instead of `let` expressions, to reduce nesting.
Nested `when` expressions can be merged into a single compound `when` expression.
This use of `define-values` is unnecessary.
These nested `for` loops can be replaced by a single `for*` loop.
| (define id/name (place-channel-get local-chan)) | ||
| (define id (list-ref id/name 0)) | ||
| (define name (list-ref id/name 1)) | ||
| (match-define (list id name) id/name) |
There was a problem hiding this comment.
How does the refactoring know the list has only two elements?
There was a problem hiding this comment.
It doesn't. Resyntax is assuming that if it contained more that'd probably be an unexpected bug and you'd prefer it be an error.
There was a problem hiding this comment.
FWIW, I tend to use list-ref as a selector lists, so the omission of some list element doesn't imply the list doesn't have more elements.
There was a problem hiding this comment.
The rule only fires when it sees a sequence of (define id (list-ref ...)) expressions that use contiguous constant indices and start at 0, so if you omit one it won't try to refactor it. This code, for instance, won't be refactored:
(define x (list-ref pt 0))
(define z (list-ref pt 2))That seems to work out decently enough in practice, but let me know if it causes an issue. There might be ways to make it more accurate.
Resyntax fixed 20 issues in 3 files.
let-to-definenested-when-to-compound-whenlist-element-definitions-to-match-definewhen-expression-in-for-loop-to-when-keywordprintf-to-displayand-let-to-condnested-for-to-for*define-values-values-to-definehash-set!-ref-to-hash-update!cond-let-to-cond-define