[plt-scheme] Fun with phases! function application is not allowed, because no #%app syntax transformer is bound

From: Ryan Culpepper (ryanc at ccs.neu.edu)
Date: Tue May 29 09:31:05 EDT 2007

On Tue, 2007-05-29 at 13:58 +0100, Noel Welsh wrote:
> Hi all,
> 
> I have a macro that generates a complaint thus:
> 
> Welcome to MzScheme v370.2 [3m], Copyright (c) 2004-2007 PLT Scheme Inc.
> parse.ss:62:10: compile: bad syntax; function application is not
> allowed, because no #%app syntax transformer is bound in:
> (make-FunDecl (name->c-name (quote v+.)) (make-function-parameters
> (list (cons (quote a) F64Vector))) (make-type F64) (list (make-VarDecl
> (quote result) F64) (let ((var-posn (symbol-append (quote x) (quote
> _posn)))) (make-ForLoop (list (make-VarDecl (qu...
> 
> I'm writing a compiler for a limited set of comprehensions.  The
> important parts are:
> 
>    - module ast defines the AST
>    - module parse requires ast.ss and contains a function, parse, that
> converts syntax to the syntax of AST construction.

In general, if you have a module with functions that are called to
produce syntax for some macro, you need to require-for-template
'mzscheme' and any other module whose bindings you refer to in the
syntax you produce.

So in your case, module parse should have the following:
  (require-for-template mzscheme)
  (require-for-template ast)

You do not need to require (as in just plain 'require') ast from parser.
The parser is only used at compile time, but you don't ever create AST
nodes at compile time.

The rules would be different if you were producing AST nodes at compile
time. Then instead of 'require-for-template', you would want 'require'.

>   (define (parse stx)
>     (syntax-case stx ()
>       [(define-cc (name [param type] ...) return body)
>        (with-syntax ([body-expr (parse-body (syntax return) (syntax body))])
>          (syntax
>           (make-FunDecl (name->c-name (quote name))
>                         (make-function-parameters
>                          (list (cons (quote param)
>                                      type) ...))
>                         (make-type return)
>                         body-expr)))]))
> 
>   - module cc requires-for-syntax parse.ss and contains a macro
> define-cc that calls parse
> 
>   (define-syntax (define-cc stx)
>     (syntax-case stx ()
>       [(define-cc (name [arg type] ...) return
>          body)
>        (with-syntax ([ast (parse stx)])
>          (syntax
>           (begin
>             (compile-ec (quote name) ast)
>             (define name
>               (if (shared-object-exists? (quote name))
>                   (load-function (quote name)
>                                  (make-function-type (list type ...) return))
>                   (lambda (arg ...)
>                     body))))))]))
> 
> >From a bit of searching I gather my error message indicates a phase
> problem, but I don't really understand how it is occurring.  I've
> tried a few things with require-for-template but to no effect.

That error, "no #%app syntax transformer is bound", is usually caused a
required-for-syntax module is producing code but neglected to
require-for-template mzscheme.

It can also be caused by turning flat data into syntax without giving it
the right lexical context, for example with (datum->syntax-object
#f ...) or implicitly with quasisyntax/unsyntax or with-syntax.

Ryan

> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.