resyntax icon indicating copy to clipboard operation
resyntax copied to clipboard

Pull `let` out of function arguments

Open jackfirth opened this issue 1 year ago • 1 comments

#lang resyntax/test

test: "let in function argument can be extracted"
--------------------
#lang racket
(define (f)
  (g (let ([x 42])
        (* x 2))
      (let ([y 100])
        (* y 3))))
--------------------
--------------------
#lang racket
(define (f)
  (define x 42)
  (define y 100)
  (g (* x 2)
     (* y 3)))
--------------------

This is only safe when it can be proved that g isn't a macro and that the surrounding expression is a function application expression. The best way to do this would probably be for either Resyntax or the Racket macro expander to look at the expanded code and add a syntax property to all function application expressions.

jackfirth avatar Nov 30 '24 00:11 jackfirth

Note: this can change evaluation order and may not be safe when some of the argument expressions have side effects.

jackfirth avatar Nov 30 '24 01:11 jackfirth