On this page:
Resyntax
9.2

Resyntax🔗ℹ

 (require resyntax) package: resyntax

Resyntax is a refactoring tool for Racket. The tool can be guided by refactoring rules, which are macro-like functions defined in terms of syntax-parse that specify how to search for and refactor different coding patterns. Resyntax comes with a standard set of refactoring rules that improve code written in #lang racket or #lang racket/base. For example, consider the following program:

"my-program.rkt"

#lang racket/base
 
(define (swap x y)
  (let ([t (unbox x)])
    (set-box! x (unbox y))
    (set-box! y t)))

This program uses let unnecessarily. The let expression can be replaced with a define form, reducing the indentation of the code. Resyntax is capable of detecting and automatically fixing this issue. Running resyntax fix --file my-program.rkt rewrites the above to the following:

"my-program.rkt"

#lang racket/base
 
(define (swap x y)
  (define t (unbox x))
  (set-box! x (unbox y))
  (set-box! y t))

To see a list of suggestions that Resyntax would apply, use resyntax analyze instead of resyntax fix. Each suggestion includes an explanation of why the change is being recommended.

    1 The Resyntax Command-Line Interface

      1.1 Installation

      1.2 Running resyntax analyze

      1.3 Running resyntax fix

    2 Refactoring Rules and Suites

      2.1 Exercising Fine Control Over Comments

      2.2 Narrowing the Focus of Replacements

      2.3 Resyntax’s Default Rules

      2.4 What Makes a Good Refactoring Rule?

    3 Testing Refactoring Rules

      3.1 Basic Test Syntax

      3.2 Code Blocks

      3.3 Test Statements

      3.4 Running Resyntax Tests

    4 The Resyntax Grimoire

      4.1 Source Code

        4.1.1 Basic Source Operations

        4.1.2 Parsing, Expanding, and Compiling Sources

      4.2 Source Groups

      4.3 Syntax Paths

        4.3.1 Original Syntax Paths and Formatting Preservation

        4.3.2 Basic Syntax Path Operations

        4.3.3 Operating on Syntax Objects with Syntax Paths