|
17 | 17 | resyntax/default-recommendations/private/lambda-by-any-name |
18 | 18 | resyntax/default-recommendations/private/let-binding |
19 | 19 | resyntax/default-recommendations/private/list-function |
| 20 | + resyntax/default-recommendations/private/literal-constant |
20 | 21 | resyntax/default-recommendations/private/metafunction |
21 | 22 | resyntax/default-recommendations/private/syntax-equivalence |
22 | 23 | resyntax/default-recommendations/private/syntax-identifier-sets |
@@ -436,6 +437,24 @@ return just that result." |
436 | 437 | nested.body ...)) |
437 | 438 |
|
438 | 439 |
|
| 440 | +(define-refactoring-rule named-let-loop-to-for-in-range |
| 441 | + #:description "This named `let` expression is equivalent to a `for` loop that uses `in-range`." |
| 442 | + #:literals (let when < +) |
| 443 | + (let loop:id ([x:id start:expr]) |
| 444 | + (when (< x2:id (~or stop:id stop:literal-constant)) |
| 445 | + body ...+ |
| 446 | + (loop2:id (+ x3:id (~or step:id step:literal-constant))))) |
| 447 | + #:when (free-identifier=? (attribute x) (attribute x2)) |
| 448 | + #:when (free-identifier=? (attribute x) (attribute x3)) |
| 449 | + #:when (free-identifier=? (attribute loop) (attribute loop2)) |
| 450 | + #:when (or (not (identifier? (attribute step))) |
| 451 | + (identifier-binding-unchanged-in-context? (attribute step) this-syntax)) |
| 452 | + #:when (not (syntax-find-first #'(body ...) id:id |
| 453 | + #:when (free-identifier=? (attribute id) (attribute loop)))) |
| 454 | + (for ([x (in-range start stop step)]) |
| 455 | + body ...)) |
| 456 | + |
| 457 | + |
439 | 458 | (define-refactoring-rule named-let-loop-to-for/list |
440 | 459 | #:description "This named `let` expression is equivalent to a `for/list` loop." |
441 | 460 | #:literals (let cond else null? empty? null quote car first cdr rest cons) |
@@ -654,6 +673,7 @@ return just that result." |
654 | 673 | list->set-to-for/set |
655 | 674 | list->vector-to-for/vector |
656 | 675 | map-to-for |
| 676 | + named-let-loop-to-for-in-range |
657 | 677 | named-let-loop-to-for/and |
658 | 678 | named-let-loop-to-for/first-in-vector |
659 | 679 | named-let-loop-to-for/list |
|
0 commit comments