I've run across a few things mentioning cooperating macros, something I'm working through.<div><br></div><div>Consider the following in a source file "nest.rkt"</div><div><a href="https://gist.github.com/4090877">https://gist.github.com/4090877</a><br>
</div><div><br></div><div>So in this example each expansion of the two defined macros in the `nest' module sees mutually mutable state at meta level 1.<br></div><div><br></div><div>And of course in a separate source module, say "bird-watcher.rkt" with the following.</div>
<div><br></div><div><div>#lang racket</div><div><br></div><div>(require "nest.rkt")</div><div><br></div><div>(define the-nest </div><div> (begin</div><div> (daddy-brings-worms) </div><div> (daddy-brings-worms)))</div>
<div><br></div><div>the-nest</div></div><div><br></div><div>;; end-of-module</div><div><br></div><div>One sees that the mutable state is not maintained across modules. i.e., Not cooperating. All, I'm guessing, a direct consequence of the "Immutable Laws Of Flatt" (ILOF), "You Want It When", and "Modules, Visitations and Instantiations, Oh My".</div>
<div><br></div><div>BUT, the ILOF has a backdoor[1], there exists a meta level wormhole which allows state to tunnel through modules and expansions. If one were to use `define-syntax' at compile time (during meta level 1) to bind a non-procedure value, one can rat-hole state which is subsequently accessible via `syntax-local-value' in an a different macro expansion at meta level 1, in a different module. i.e., the macros now can cooperate. Here I'm taking "cooperate" as synonymous with shared mutable state.<br>
</div><div><br></div><div>Based on what I think I understand, I can rejigger my bird net examples to cooperate using the wormhole. </div><div><br></div><div>So assuming the above is more-or-less correct, can cooperating macros be accomplished solely via the application of module require / provide at proper meta levels. One one hand, I'm visualizing a `define-syntax' binding a non-procedure value at compile time (meta 1) as in essence pushing the value up into meta 2. And the `syntax-local-value' as reaching out from meta 1 into meta 2 to fetch the state down. It's global because meta layer 2 is a single global environment in which meta 1 syntax transformers are evaluated.</div>
<div><br></div><div>On the other, other hand I visualize that during module visitations and instantiations the _only_ thing which can _cross_ meta levels is syntax. i.e. syntax at meta level N can be lifted into meta level N+1, transformed and returned back to meta level N. But as only syntax crosses meta boundaries, hence the define-syntax and syntax-local-value backdoor.</div>
<div><br></div><div>Or another way of phrasing the question, "Can one write cooperating macros without resorting to the use of `define-syntax' and `syntax-local-value'". If yes, how?</div><div><br></div>
<div><br></div><div>Thanks,</div><div><br></div><div><br>Ray</div><div><br></div><div><br></div><div>[1] Seems the only true immutable law in CS is, there's always a backdoor.</div>