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

From: YC (yinso.chen at gmail.com)
Date: Mon Aug 9 14:00:10 EDT 2010

On Mon, Aug 9, 2010 at 6:00 AM, rafkind <rafkind at cs.utah.edu> wrote:

> 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.

Ah - that solved it. Thanks!

So does (begin-for-syntax ...) automatically manage the above for the
function?  I am trying to grok the difference but not sure if I got it:

1) when begin-for-syntax is used - the function is introduced in phase 1,
which handles syntax matching at phase 0, so it works correctly

2) when (require (for-syntax)) is used - the function was defined in phase
0, but is imported into phase 1... would it not handle syntax matching at
phase 0?

Then is it the case that for-syntax does not "shift" the phase of the
function in question? So the function stays at phase 0 so it needs phase -1

3) Is it a best practice then all such module should all have (for-template
...) whether the functions have syntax-case literals defined?  It seems that
the syntax-case matches the syntax shapes if they do not involve literals
(in the literal.ss it results in matching of both the empty and the if
clause), i.e. the only time I've noticed it not working is when literals are

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20100809/cef89c0b/attachment.html>

Posted on the users mailing list.