[plt-scheme] Issues with expand

From: Danny Yoo (dyoo at hkn.eecs.berkeley.edu)
Date: Wed Aug 9 13:18:01 EDT 2006


On Wed, 9 Aug 2006, Casey Klein wrote:

> I've run into two confusing issues with "expand."
>
> 1. Running the module below produces the error "require: broken compiled
> code (phase 0, defn-phase 0): cannot find module m in: x."
>
> (module m mzscheme
>  (define x 42)
>  (expand #'(module n mzscheme x)))


Hi Casey,

What's happening is that, within the syntax that has been built, the 
syntax is being enriched with lexical binding information from the 
enclosing module.  Try using the following code to help erase that 
information:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(module m mzscheme
   (define (erase-identifier-binding stx)
     (syntax-case stx ()
       [()
        (datum->syntax-object #f '() stx stx)]
       [(a . b)
        (let ([ea (erase-identifier-binding #'a)]
              [eb (erase-identifier-binding #'b)])
          (datum->syntax-object #f `(,ea . ,eb) stx stx))]
       [_
        (datum->syntax-object
         #f (syntax-object->datum stx) stx stx)]))


   (expand (erase-identifier-binding
            #'(module n mzscheme
                (define x 42)
                x))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


I hope this helps!


Posted on the users mailing list.