[racket-dev] cross-phase syntax constants
On Fri, Jul 6, 2012 at 11:00 AM, Matthew Flatt <mflatt at cs.utah.edu> wrote:
> I find the example too abstract to understand why the computation
> happens at the "wrong phase" when you adjust the code with
> `begin-for-syntax'. Can you explain a little more, maybe with a more
> concrete example?
>
> Just in case, here's the code that I think you have in mind for "wrong
> phase":
I had not realized that I could sensibly wrap a module in a
`begin-for-syntax`. What is the semantic difference between that and
a "plain" submodule (other than my example working)? I will try that,
and see if it works for my purposes.
> At Thu, 5 Jul 2012 17:17:08 -0400, Sam Tobin-Hochstadt wrote:
>> I'd like to write a program basically like this:
>>
>> #lang racket/load
>>
>> (module m1 racket
>> (define l (list #'l))
>> (provide l))
>>
>> (module m2 racket
>> (require (for-syntax 'm1))
>> (define-syntax (mac stx)
>> #`(module* sub #f
>> (length (list #,(car l)))))
>> (provide mac))
>>
>> (module m3 racket
>> (require 'm2)
>> (mac))
>>
>> But I can't come up with any way to `require` m1 appropriately so that
>> `l` is bound in the generated submodule. If I wrap the body of the
>> submodule in `begin-for-syntax`, then it works, but then loading the
>> submodule does the computation at the wrong phase. So another
>> solution would be `dynamic-require-for-template`, if that's feasible.
>> --
>> sam th
>> samth at ccs.neu.edu
--
sam th
samth at ccs.neu.edu