[plt-scheme] macro differences in REPL vs. in a module?

From: Benderjg2 at aol.com (Benderjg2 at aol.com)
Date: Fri Sep 13 21:50:22 EDT 2002

Hi!

> > The full example is rather long, but complains:
> >   compile: bad syntax; function application is not allowed, because no 
> #%app 
> > syntax transformer is bound in: ...
> 
> After giving it some thought, I don't have any good guesses.

I have managed to fix my macro, but also to formulate a far more consise 
example of this problem (given below). In the following example, if I 
"inline" the helper in my macro, everything behaves correctly. But in the 
case below, I get the following error when my macro is used within a module:
a.ss:8:5: compile: bad syntax; function application is not allowed, because 
no #%app syntax transformer is bound in: (cons 1 2)

As before, when this macro is used in the REPL in DrScheme, the macro 
"works". In this case, the macro is expanded, and the result is evaluated to 
(1 . 2) as one would expect.

The trick to fixing my complte define-struct/prop macro was to move the 
"helper" code into the body of my syntax case macro.

In principle, I could, sort of, understand that there is a problem with 
referencing a binding of cons in an instantiation of mzscheme in a different 
phase, and feeding this syntax object back to the value-time environment of 
module c. But why does it "work" in the REPL, if that is the case?

Jim

---------------------------
; c.ss

(module c mzscheme
  
  (require "b.ss")
  
  (my-cons 1 2))

---------------------------
; b.ss

(module b mzscheme
  
  (provide my-cons)
  
  (require-for-syntax "a.ss")
  
  (define-syntax (my-cons stx)
    (syntax-case stx ()
      ((_ a b)
       (helper #`a #`b)))))

---------------------------
; a.ss

(module a mzscheme
  
  (provide helper)
  
  (define (helper first rest)
    #`(cons #,first #,rest)))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20020913/dc335463/attachment.html>

Posted on the users mailing list.