[plt-scheme] using a defined procedure in a syntax-case form

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon May 12 19:16:17 EDT 2008

At Mon, 12 May 2008 21:06:08 +0100, Filipe Cabecinhas wrote:
> Hi,
> 
> I'm trying to use a helper function I defined in the same module in a  
> syntax-case form, but I keep getting "unbound variable" errors.
> 
> Here's an example:
> --------------------------
> #lang scheme
> 
> (define (a str)
>    (string-append "a" str))
> 
> (define-syntax b
>    (lambda (stx)
>      (syntax-case stx ()
>        ((_ str)
>         (with-syntax ([str2 (datum->syntax #'str (a (syntax->datum  
> #'str)))])
>           #'str2)))))
> --------------------------
> 
> error: expand: unbound variable in module (transformer environment)  
> in: a

The implementation of a macro cannot call a function that exists only
at run time.

If you want `a' to exist at macro-expansion time, instead, define it with
`define-for-syntax':

 (define-for-syntax (a str)
    (string-append "a" str))


Matthew



Posted on the users mailing list.