[racket] syntax-case literals matching in a procedure defined via begin-for-syntax vs (require (for-syntax ...))

From: rafkind (rafkind at cs.utah.edu)
Date: Mon Aug 9 09:00:15 EDT 2010

On Mon, 9 Aug 2010 01:23:00 -0700, YC <yinso.chen at gmail.com> wrote:
> Hi all -
> 
> I am running into a difference of behaviors when I define a procedure
with
> syntax-case via `begin-for-syntax` versus requiring it from another
module
> via (require (for-syntax ...)).  It seems that if the procedure has
> syntax-case literals defined, the literal-matching works if the
procedure
> is
> defined via `begin-for-syntax`, but not when imported via
> `require`/`for-syntax`.
> 
> Any idea on what I am missing/misusing here?
> 
> Below is an example with literal.ss and test-literal.ss showing that it
> does
> not work:
> 
> ;; literal.ss - cond* matches a cond-like syntax and convert it to an
> nested
> if syntax. has an `else` syntax-case literal
> #lang scheme/base
> (define (cond* stx)
>   (syntax-case stx (*else*)
>     ((~)
>      #`(void))
>     ((~ (*else* exp exp2 ...))
>      #`(begin (void) exp exp2 ...))
>     ((~ (test exp exp2 ...) rest ...)
>      #`(if test
>            (begin exp exp2 ...)
>            #,(cond* #`(cond* #,@#'(rest ...)))))
>     ))
> 
> (provide cond*)
> 

You need a (require (for-template scheme/base)) in the 'literal.ss' file
because the function is at phase 0 producing syntax at a lower phase (-1,
which is template), so you need to import the bindings from scheme/base for
that phase.


Posted on the users mailing list.