[racket] local-expand 'module-begin
Hello list,
I'm trying to use local-expand within a custom #%module-begin in order
to inspect the expansion and its side effects, but this does not appear
to work in all cases. Am I using local-expand correctly? Are there
restrictions to its ability to handle a module body?
To demonstrate. This code runs OK
#lang racket
(require (for-meta 2 racket/base))
(define x 0)
(begin-for-syntax
(begin-for-syntax
(define x 2)))
but if I instead try to local-expand the same module body with
#lang racket
(module le-lang racket
(provide
(except-out (all-from-out racket) #%module-begin)
(rename-out [module-begin #%module-begin]))
(define-syntax (module-begin stx)
(syntax-case stx ()
((_ . bs)
(local-expand
#'(#%module-begin . bs)
'module-begin null)))))
(module le-module (submod ".." le-lang)
(require (for-meta 2 racket/base))
(define x 0)
(begin-for-syntax
(begin-for-syntax
(define x 2))))
then I get the error
module: duplicate definition for identifier
at: x
in: (define-values (x) (quote 2))