[plt-scheme] Difficulty with generate-temporaries

From: Richard C. Cobbe (cobbe at ccs.neu.edu)
Date: Tue Aug 3 11:38:19 EDT 2004

Greetings, all.

I'm having some strange problems with a macro whose definition uses
generate-temporaries.  A minimal example follows:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; util.ss
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(module util mzscheme
  
  (provide with-public-inspector)
  
  (define-syntax with-public-inspector
    (lambda (stx)
      (syntax-case stx ()
        [(kw defns ...)
         (with-syntax ([(old-inspector)
                        (generate-temporaries #'(old-inspector))])
           #'(begin
               (define old-inspector (current-inspector))
               (current-inspector (make-inspector))
               defns ...
               (current-inspector old-inspector)))]))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; module-program.ss
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(module module-program mzscheme

  (require "util.ss")

  (with-public-inspector
   (define-struct foo (bar)))

  (define f (lambda () (make-foo 3))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; textual-program.ss
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(require "util.ss")

(with-public-inspector
 (define-struct foo (bar)))

(define f (lambda () (make-foo 3)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Save the three snippets of code above in the indicated filenames.
Executing util.ss in the module language (DrScheme 208-cvs26jul2004)
works as expected; executing module-program.ss in the module language
also works fine.  However, executing textual-program.ss in the textual
language produces the following error message:

    compile: bad syntax; reference to top-level identifiers is not
    allowed, because no #%top syntax transformer is bound in:
    old-inspector1

and nothing is highlighted in the original source window.

So it appears that I can't use with-public-inspector outside of a
module.

What's going on here?  Ryan Culpepper thought it might have something to
do with a strange interaction between generate-temporaries and begin,
but he wasn't sure.  Is this a bug in my code, a bug in the macro
system, or something else entirely?

Richard


Posted on the users mailing list.