Closed Metaxal closed 2 years ago
Things seem fine here actually. I took both the examples Alexis gave and wrapped them in functions (so that resyntax
would see that they're in tail position) and manually applied the let-to-define
migration myself. Here's what I ended up with:
(define (f)
(let ([x 'outer])
(define-syntax-rule (m a)
(let ([a 'inner]) x))
(m x)))
(define (f2)
(define x 'outer)
(define-syntax-rule (m a)
(let ([a 'inner]) x))
(m x))
(define (g)
(let ([x 'outer])
(define-syntax-rule (m a)
(begin
(define a 'inner)
x))
(m x)))
(define (g2)
(define x 'outer)
(define-syntax-rule (m a)
(begin
(define a 'inner)
x))
(m x))
Results:
(f)
and (f2)
both produce 'outer
, so no problems thereg2
fails to compile, as it introduces a duplicate binding. The current let-to-define
rule isn't able to detect this, because it doesn't actually locally expand the body of the let when it tries to determine if the rewrite would make duplicate bindings. So fixing #10 would address this issue.Closing this as a duplicate of #10.
https://github.com/jackfirth/resyntax/blob/7fc36a29268f1210efa840c587881ad3fb4286e5/default-recommendations/let-binding-suggestions.rkt#L40
A recent example by Alexis King demonstrates that there may be more tricky cases where a
let
cannot be turned into adefine
: https://groups.google.com/g/racket-users/c/XkGnOMQKi2g/m/3AJJGaC4AgAJ?utm_medium=email&utm_source=footer&pli=1Not sure how to detect or handle this one :-/