Thanks for answering on a Friday night. I'll limit my questions to one and do some more homework now that you've reduced the search space.<div><br></div><div>Regarding,</div><div><br><div><span style="font-family:arial,sans-serif;font-size:13px">"The *only* way for module A to affect the compilation of module B in any way is for module B to require (directly or indirectly) module A.</span><br style="font-family:arial,sans-serif;font-size:13px">
<br style="font-family:arial,sans-serif;font-size:13px"><span style="font-family:arial,sans-serif;font-size:13px">And the only way to make a compile-time side-effect in module A "persistent", so it will affect the compile-time state of other module compilations is to put it in a 'begin-for-syntax'."</span><br>
</div><div><br></div><div><font face="arial, sans-serif">True or False, anything you can do with begin-for-syntax can be done via a module, providing and subsequently requiring where needed via: </font></div><div><font face="arial, sans-serif">(require (for-syntax ...))</font></div>
<div><font face="arial, sans-serif">(require (only-meta-in ...))</font></div><div><font face="arial, sans-serif">(require (for-meta 1 ...))</font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">Thanks in advance,</font></div>
</div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">Ray</font></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Nov 16, 2012 at 6:05 PM, Ryan Culpepper <span dir="ltr"><<a href="mailto:ryan@cs.utah.edu" target="_blank">ryan@cs.utah.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On 11/16/2012 05:16 PM, Ray Racine wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I've run across a few things mentioning cooperating macros, something<br>
I'm working through.<br>
<br>
Consider the following in a source file "nest.rkt"<br>
<a href="https://gist.github.com/4090877" target="_blank">https://gist.github.com/<u></u>4090877</a><br>
<br>
So in this example each expansion of the two defined macros in the<br>
`nest' module sees mutually mutable state at meta level 1.<br>
<br>
And of course in a separate source module, say "bird-watcher.rkt" with<br>
the following.<br>
<br>
#lang racket<br>
<br>
(require "nest.rkt")<br>
<br>
(define the-nest<br>
(begin<br>
(daddy-brings-worms)<br>
(daddy-brings-worms)))<br>
<br>
the-nest<br>
<br>
;; end-of-module<br>
<br>
One sees that the mutable state is not maintained across modules. i.e.,<br>
Not cooperating. All, I'm guessing, a direct consequence of the<br>
"Immutable Laws Of Flatt" (ILOF), "You Want It When", and "Modules,<br>
Visitations and Instantiations, Oh My".<br>
</blockquote>
<br></div>
Yes. To summarize: the expansion/compilation of each module starts with a fresh state, which is then initialized with the compile-time parts of the modules it depends on.<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
BUT, the ILOF has a backdoor[1], there exists a meta level wormhole<br>
which allows state to tunnel through modules and expansions. If one<br>
were to use `define-syntax' at compile time (during meta level 1) to<br>
bind a non-procedure value, one can rat-hole state which is subsequently<br>
accessible via `syntax-local-value' in an a different macro expansion at<br>
meta level 1, in a different module. i.e., the macros now can cooperate.<br>
Here I'm taking "cooperate" as synonymous with shared mutable state.<br>
<br>
Based on what I think I understand, I can rejigger my bird net examples<br>
to cooperate using the wormhole.<br>
</blockquote>
<br></div>
No, that's not a back door, because you still get a fresh state and then you execute the definition again. So if you did something like<br>
<br>
(define-syntax the-nest-state (box (cons 0 0)))<br>
<br>
and then mutated the box during the expansion of module A, then when you start expanding module B you execute that syntax definition again, so module B starts out with a fresh box holding (cons 0 0).<br>
<br>
--<br>
<br>
The *only* way for module A to affect the compilation of module B in any way is for module B to require (directly or indirectly) module A.<br>
<br>
And the only way to make a compile-time side-effect in module A "persistent", so it will affect the compile-time state of other module compilations is to put it in a 'begin-for-syntax'. (Actually, there are a few other ways, but they take longer to explain.)<br>
<br>
--<br>
<br>
I'll stop here in case you want to reformulate the questions in your next few paragraphs based on my answers so far.<br>
<br>
Ryan<br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
So assuming the above is more-or-less correct, can cooperating macros be<br>
accomplished solely via the application of module require / provide at<br>
proper meta levels. One one hand, I'm visualizing a `define-syntax'<br>
binding a non-procedure value at compile time (meta 1) as in essence<br>
pushing the value up into meta 2. And the `syntax-local-value' as<br>
reaching out from meta 1 into meta 2 to fetch the state down. It's<br>
global because meta layer 2 is a single global environment in which meta<br>
1 syntax transformers are evaluated.<br>
<br>
On the other, other hand I visualize that during module visitations and<br>
instantiations the _only_ thing which can _cross_ meta levels is syntax.<br>
i.e. syntax at meta level N can be lifted into meta level N+1,<br>
transformed and returned back to meta level N. But as only syntax<br>
crosses meta boundaries, hence the define-syntax and syntax-local-value<br>
backdoor.<br>
<br>
Or another way of phrasing the question, "Can one<br>
write cooperating macros without resorting to the use of `define-syntax'<br>
and `syntax-local-value'". If yes, how?<br>
<br>
<br>
Thanks,<br>
<br>
<br>
Ray<br>
<br>
<br>
[1] Seems the only true immutable law in CS is, there's always a backdoor.<br>
<br>
<br></div>
____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/<u></u>users</a><br>
<br>
</blockquote>
<br>
</blockquote></div><br></div>