New rule: `simplify-named-let-initialization`
Nadie ha tomado este issue todavía.
Evaluación
Este issue todavía no se ha evaluado.
Descripción
Rule summary
Old scheme code that doesn't use internal definitions sometimes uses complex named let loops with very large expressions used as the initial values for the named let's arguments. Since all of a named let's initial arguments are evaluated before anything in the named let is, it's more readable to extract complex initial value expressions into definitions preceding the named let.
This should only be done for named let argument initialization expressions that take up multiple lines, and it's only safe when the other initialization expressions are pure. It's also only possible in a definition context. The variable name chosen for the initial value should be the corresponding named let argument variable name prefixed with init-.
This rule should not be included alongside the let-replacement rules, since it isn't actually replacing a let binding with a define: it's introducing a new define binding to make an existing let binding easier to read.
Test case
#lang resyntax/test
test: "original code should be refactorable to new code"
--------------------
#lang racket
(define (f a b c)
(let loop ([x (+ 1 2 3)]
[y (if (a)
(b)
(c))])
(loop x y)))
====================
#lang racket
(define (f a b c)
(define init-y
(if (a)
(b)
(c)))
(let loop ([x (+ 1 2 3)]
[y init-y)])
(loop x y)))
--------------------
No-change test case
#lang resyntax/test
no-change-test: "code not refactorable"
--------------------
#lang racket
(define (f a b c)
(let loop ([x (displayln "foo")]
[y (if (a)
(b)
(c))])
(loop x y)))
--------------------
Additional context
Saw this in racket/scribble#535, specifically this commit.
- Lenguaje dominante
- Racket
- Estrellas
- 70
- Forks
- 11
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de jackfirth/resyntax
-
Grimoire docs need examples Abiertodocumentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
documentation
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
-
testing
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
-
testing
Dificultad 3/5 1-2 días Aptitud para principiantes 75/100
-
testing
Dificultad 4/5 3-5 días Aptitud para principiantes 68/100