@@ -437,130 +437,19 @@ return just that result."
437437 nested.body ... ))
438438
439439
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-
458- (define-refactoring-rule named-let-loop-to-for/list
459- #:description "This named `let` expression is equivalent to a `for/list` loop. "
460- #:literals (let cond else null? empty? null quote car first cdr rest cons)
461- (let loop:id ([vs:id init-list])
462- (cond
463- [(:empty-predicate-by-any-name vs2:id) :empty-list-by-any-name]
464- [else
465- loop-body:expr ...
466- (cons loop-element:expr (loop2:id (:rest-by-any-name vs3:id)))]))
467- #:when (log-resyntax-rule-condition (free-identifier=? #'loop #'loop2 ))
468- #:when (log-resyntax-rule-condition (free-identifier=? #'vs #'vs2 ))
469- #:when (log-resyntax-rule-condition (free-identifier=? #'vs #'vs3 ))
470- #:when (log-resyntax-rule-condition
471- (not
472- (for/or ([body-stx (in-list (cons #'loop-element (attribute loop-body)))])
473- (syntax-find-first body-stx
474- (~and (~var usage (expression-directly-enclosing (attribute vs)))
475- (~not (:first-by-any-name _ )))))))
476- #:cut
477440
478- #:with element-id (depluralize-id #'vs )
479-
480- #:with (modified-result-element modified-body ... )
481- (for/list ([body-stx (cons #'loop-element (attribute loop-body))])
482- (syntax-traverse body-stx
483- [(:first-by-any-name vs-usage:id)
484- #:when (free-identifier=? (attribute vs-usage) (attribute vs))
485- (attribute element-id)]))
486-
487- (for/list ([element-id (in-list init-list)])
488- modified-body ...
489- modified-result-element))
490-
491-
492- (define-refactoring-rule named-let-loop-to-for/and
493- #:description "This named `let` expression is equivalent to a `for/and` loop. "
494- #:literals (let cond else )
495- (let loop:id ([vs:id init-list])
496- (cond
497- [(:empty-predicate-by-any-name vs2:id) #true ]
498- [element-condition:expr (loop2:id (:rest-by-any-name vs3:id))]
499- [else #false ]))
500-
501- #:when (free-identifier=? (attribute loop) (attribute loop2))
502- #:when (free-identifier=? (attribute vs) (attribute vs2))
503- #:when (free-identifier=? (attribute vs) (attribute vs3))
504- #:when (not (syntax-find-first (attribute element-condition)
505- (~and (~var usage (expression-directly-enclosing (attribute vs)))
506- (~not (:first-by-any-name _ )))))
507- #:cut
508441
509- #:with element-id (depluralize-id (attribute vs))
510- #:with modified-element-condition
511- (syntax-traverse (attribute element-condition)
512- [(:first-by-any-name vs-usage:id)
513- #:when (free-identifier=? (attribute vs-usage) (attribute vs))
514- (attribute element-id)])
515-
516- (for/and ([element-id (in-list init-list)])
517- modified-element-condition))
518-
519-
520- (define-refactoring-rule named-let-loop-to-for/or
521- #:description "This named `let` expression is equivalent to a `for/or` loop. "
522- #:literals (let cond else )
523- (let loop:id ([vs:id init-list])
524- (cond
525- [(:empty-predicate-by-any-name vs2:id) #false ]
526- [element-condition:expr #true ]
527- [else (loop2:id (:rest-by-any-name vs3:id))]))
528-
529- #:when (free-identifier=? (attribute loop) (attribute loop2))
530- #:when (free-identifier=? (attribute vs) (attribute vs2))
531- #:when (free-identifier=? (attribute vs) (attribute vs3))
532- #:when (not (syntax-find-first (attribute element-condition)
533- (~and (~var usage (expression-directly-enclosing (attribute vs)))
534- (~not (:first-by-any-name _ )))))
535- #:cut
536442
537- #:with element-id (depluralize-id (attribute vs))
538- #:with modified-element-condition
539- (syntax-traverse (attribute element-condition)
540- [(:first-by-any-name vs-usage:id)
541- #:when (log-resyntax-rule-condition (free-identifier=? (attribute vs) (attribute vs-usage)))
542- (attribute element-id)])
543-
544- (for/or ([element-id (in-list init-list)])
545- modified-element-condition))
546-
547-
548- (define-refactoring-rule named-let-loop-to-for/first-in-vector
549- #:description "This loop can be replaced by a simpler, equivalent `for/first` loop. "
550- #:literals (let add1 + vector-length vector-ref if and <)
551- (let loop1:id ([i1:id 0 ])
552- (and (< i2:id (vector-length vec1:id))
553- (let ([x:id (vector-ref vec2:id i3:id)])
554- (if condition:expr
555- true-branch:expr
556- (loop2:id (~or (add1 i4:id) (+ i4:id 1 ) (+ 1 i4:id)))))))
557- #:when (and (log-resyntax-rule-condition (free-identifier=? #'loop1 #'loop2 ))
558- (log-resyntax-rule-condition (free-identifier=? #'i1 #'i2 ))
559- (log-resyntax-rule-condition (free-identifier=? #'i1 #'i3 ))
560- (log-resyntax-rule-condition (free-identifier=? #'i1 #'i4 ))
561- (log-resyntax-rule-condition (free-identifier=? #'vec1 #'vec2 )))
562- (for/first ([x (in-vector vec1)] #:when condition)
563- true-branch))
443+
444+
445+
446+
447+
448+
449+
450+
451+
452+
564453
565454
566455(define-refactoring-rule or-let-in-for/and-to-filter-clause
@@ -621,18 +510,7 @@ return just that result."
621510 (for-id (clause-before ... #:do [expr] clause-after ... ) body ... ))
622511
623512
624- (define-refactoring-rule named-let-read-loop-to-for-in-port
625- #:description
626- "A named `let` that repeatedly calls `read` can be rewritten to a `for` loop using `in-port`. "
627- #:literals (let unless read eof-object?)
628- (let loop:id ([v:id (read)])
629- (unless (eof-object? v2:id)
630- body ...
631- (loop2:id (read))))
632- #:when (free-identifier=? (attribute v) (attribute v2))
633- #:when (free-identifier=? (attribute loop) (attribute loop2))
634- (for ([v (in-port)])
635- body ... ))
513+
636514
637515
638516(define-refactoring-rule index-mutating-map-to-for/list
@@ -673,12 +551,6 @@ return just that result."
673551 list->set-to-for/set
674552 list->vector-to-for/vector
675553 map-to-for
676- named-let-loop-to-for-in-range
677- named-let-loop-to-for/and
678- named-let-loop-to-for/first-in-vector
679- named-let-loop-to-for/list
680- named-let-loop-to-for/or
681- named-let-read-loop-to-for-in-port
682554 nested-for-to-for*
683555 nested-for/and-to-for*/and
684556 nested-for/or-to-for*/or
0 commit comments