Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

New rule: `simplify-named-let-initialization`

オープン
#745 コメント 1 件 リアクション 2 件 担当者 1 名 GitHub で見る

まだ誰も着手していません。

評価

この issue はまだ評価されていません。

説明

autopilot-candidate new lint
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.

主要言語
Racket
スター
70
フォーク
11
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

jackfirth/resyntax のほかの issue

jackfirth/resyntax の issue をすべて見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。