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/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.
This tool is extremely experimental. Do not attempt to incorporate it into your projects yet. For now, the refactoring suggestions produced by resyntax are best viewed as glimpses into one possible distant future of static analysis for Racket. Feedback, questions, and ideas are all greatly appreciated and are best directed at the GitHub repository.