resyntax
resyntax copied to clipboard
Overly conservative let to define conversion
#lang racket/base
(define (test b)
(let ([x (cond
[b (define x 1)
(+ x 1)]
[else 2])])
(+ x 1)))
should successfully convert let to define. It doesn't because (define x 1)
inside the a cond
clause would have shadowed (define x (cond ...))
, but that's actually fine.
This could be solved by building a data structure containing all the information of DrRacket's binding arrows and passing that to each rule as part of the analysis. The current logic dictates that if the identifier for a let
is bound-identifier=?
to anything in the right-hand side, it can't be refactored to define
. But in this case it works because the binding for the usage in the RHS doesn't resolve to a definition that the define
-replacement would shadow. Building that data structure would be a little tricky, but probably quite useful. Onto the todo list it goes.