resyntax
resyntax copied to clipboard
Replace `for` and `set!` with `for/fold`
Saw some code in racket/drracket#691 where a rule like this would help:
#lang resyntax/test
test: "for with set! refactorable to for/fold"
--------------------
#lang racket
(define (f n)
(define xs '())
(for ([x (in-range n)])
(set! xs (cons x xs)))
xs)
--------------------
--------------------
#lang racket
(define f n
(define xs
(for/fold ([xs '()])
([x (in-range n)])
(cons x xs)))
xs)
--------------------
Might be some subtleties to this one.