[plt-scheme] erasing lexical scope --- reinventing the wheel?

From: Danny Yoo (dyoo at hkn.eecs.berkeley.edu)
Date: Tue Jun 13 15:07:04 EDT 2006

Hi everyone,

I've written a quick-and-dirty function to erase the identifier bindings 
off a syntax, and wanted to make sure I wasn't reinventing something 
that's already in a library somewhere.

Here's what it looks like:

   ;; erase-lexical-scope: syntax -> syntax
   ;; Removes identifier-binding information from a syntax, preserving
   ;; location information.
   (define (erase-lexical-scope stx)
     (define (syntax-properties stx)
       (map (lambda (f) (f stx))
            (list syntax-source syntax-line syntax-column
                  syntax-position syntax-span)))
     (syntax-case stx ()
        (datum->syntax-object #f '() stx)]
       [(a . b)
        (with-syntax ([ea (erase-lexical-scope #'a)]
                      [eb (erase-lexical-scope #'b)])
          (datum->syntax-object #f #'(ea . eb) (syntax-properties stx)))]
         #f (syntax-object->datum stx) (syntax-properties stx))]))

(I'm using this for some test-case writing involving dynamically 
generating modules and evaluating them.)

I looked around in the syntax collection but didn't find this function in 
there.  I want to see if anyone else was doing something similar.

Best of wishes!

Posted on the users mailing list.