[plt-scheme] undefined identifiers after generating (require (all-except)) statement

From: Danny Yoo (dyoo at hkn.eecs.berkeley.edu)
Date: Tue Jul 25 22:23:47 EDT 2006


On Tue, 25 Jul 2006, Kimberley Burchett wrote:

> I'm have a macro that generates (require (all-except)) statements, but
> they don't seem to actually import any identifiers.  That is, I get
> "unbound variable in module" errors when referencing identifiers that
> should have been imported.

Hi Kimberley,

Those identifiers should have the same color as the input stx. I think 
what's going on is that REQUIRE is trying to use the whole syntax object 
to introduce the identifiers non-hygienically, but that's not working out 
because the syntax object here:

>     [(_ (all-except mod id ...))
>      #`(require (all-except mod id ...))]

has a different color than the input stx, since that syntax object is 
freshly created by the macro.  If I make a change to explicitely color 
that syntax, using a combination of SYNTAX-OBJECT->DATUM and 
DATUM->SYNTAX-OBJECT, then things appear to work out:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(module m2 mzscheme
  (define-syntax (my-require stx)
    (syntax-case stx (all-except)
      [(_ (all-except mod id ...))
       (datum->syntax-object
        stx
        (syntax-object->datum
         #'(require (all-except mod id ...))))]
      [(_ mod)  ;; require entire module
       #'(require mod)]))
  (my-require (all-except m1 foo))
  (display bar))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

This does look a little weird to me though.  I have to admit that I'm 
still newbie enough that I'm not quite sure if this is the right way to 
approach the macro.


Best of wishes!


Posted on the users mailing list.