Sure, here's a toy example.

This code:

> (Loop 10
>       (begin
>         (define-values
>           [dx dy dz]
>           (values 0 0 0))
>         ; Some calculation here
>         (Accum x dx)
>         (Accum y dy)
>         (Accum z dz)))
>

Should desugar into this code:

> (letrec
>     ([loop
>       (lambda (n)
>         (begin
>           (define-values
>             [dx dy dz]
>             (values 0 0 0))
>           ; Some calculation here
>           (set! x (+ x dx))
>           (set! y (+ y dy))
>           (set! z (+ z dz)))
>         (if (< n 10)
>             (loop (+ 1 n))
>             (void)))])
>   (set! x 0)
>   (set! y 0)
>   (set! z 0)
>   (loop 0))
>

And in general, every unique id occuring in an (Accum id delta) in the loop
body should result in (set! id 0) in the prologue.

Also, some context to avoid unproductive side-conversation: I'm using
Racket's macro facility to do pre-compilation of a totally different
language. The fully-expanded program in this case is going to be a call to
a function that rewrites Racket syntax objects into strings in the syntax
of something which isn't Racket. This means that I really want my original
question answered, rather than suggestions to solve a different problem
that happens to accomplish the same thing for this toy example. The
critical pieces here are that Accum only be defined within the body of a
Loop, and that it be able to communicate outwards to effect the code
generation of the specific instantiation of Loop in which it appears.


Thomas Dickerson

Brown University
Department of Computer Science
115 Waterman St, 4th Floor
Providence, RI 02912

802-458-0637

On Fri, Jun 19, 2015 at 3:22 PM, Ryan Culpepper <ry...@ccs.neu.edu> wrote:

> On 06/19/2015 03:07 PM, Thomas Dickerson wrote:
>
>> Hi All,
>>
>> I'm trying to figure out how best to implement the following pattern of
>> macro behavior:
>>
>> Let's say we are writing Loop macro that implements a looped computation
>> over a specified body. I would like to then be able to
>> (a) introduce additional Loop-specific macros that are defined only
>> within the scope of the body
>> (b) are able to coordinate with the outer macro so as to alter its
>> generation of prologue and epilogue code.
>>
>> My best guess here is some use of local-expand with
>> syntax-local-bind-syntaxes, or perhaps syntax-parameterize, but I can't
>> quite work out the appropriate constructions.
>>
>> I've been able to implement something similar using syntax-case functions
>> on syntax objects at phase-0, by essentially implementing my own namespace
>> for macros and passing it as an explicit argument, but this loses the
>> hygiene benefits of coordinating with expand.  I had an offline discussion
>> with Shriram yesterday in which he suggested looking into ways to reify the
>> expansion-time namespace, but obviously current-namespace does the wrong
>> thing here.
>>
>
> Can you provide a small example program and describe how you want it to
> behave?
>
> Ryan
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to