[plt-scheme] syntax equivalent to doing both define-for-syntax and define?

From: Neil Van Dyke (neil at neilvandyke.org)
Date: Mon Mar 17 04:35:03 EDT 2008

Aha.  I wasn't aware that I could have top-level definitions within a 
"begin".  Thanks.

Ryan Culpepper wrote at 03/17/2008 04:15 AM:
> Neil Van Dyke wrote:
>> Is there syntax in MzScheme 372 that will have the effect of both 
>> "define-for-syntax" and "define"?
>> Basically, I'm trying to implement a new one of my infamous portable 
>> single-file Scheme libraries, and have certain procedure definitions 
>> available both in the transformer environment and the normal 
>> top-level environment.
>> I'm only interested in convenient duplicating of the syntax of the 
>> definitions, not in sharing bindings or values across phases.
> Well, you could do this:
>   (define-syntax define-for-both
>     (syntax-rules ()
>       [(define-for-both header . body)
>        (begin (define-for-syntax header . body)
>               (define header . body))]))
> Of course, that duplicates the code, which means that it is compiled 
> twice, takes up twice as much space, etc. You'll also still have to 
> live with the restrictions of 'define-for-syntax', like no forward 
> references. It might be fine for your purposes, though. The clean way 
> is what you describe below: make a module and require it in both phases.
> Ryan
>> If MzScheme 372 doesn't have a way to do this in one file, I suppose 
>> I can move the problematic functionality into a second portable 
>> library (and therefore, second PLT module) that can be both 
>> "require-for-syntax"'d and "require"'d by the first library.
>> Thanks,
>> Neil

Posted on the users mailing list.