I&#39;ve run across a few things mentioning cooperating macros, something I&#39;m working through.<div><br></div><div>Consider the following in a source file &quot;nest.rkt&quot;</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&#39; module sees mutually mutable state at meta level 1.<br></div><div><br></div><div>And of course in a separate source module, say &quot;bird-watcher.rkt&quot; with the following.</div>
<div><br></div><div><div>#lang racket</div><div><br></div><div>(require &quot;nest.rkt&quot;)</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&#39;m guessing, a direct consequence of the &quot;Immutable Laws Of Flatt&quot; (ILOF), &quot;You Want It When&quot;, and &quot;Modules, Visitations and Instantiations, Oh My&quot;.</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&#39; 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&#39; in an a different macro expansion at meta level 1, in a different module. i.e., the macros now can cooperate.  Here I&#39;m taking &quot;cooperate&quot; 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&#39;m visualizing a `define-syntax&#39; 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&#39; as reaching out from meta 1 into meta 2 to fetch the state down.  It&#39;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, &quot;Can one write cooperating macros without resorting to the use of `define-syntax&#39; and `syntax-local-value&#39;&quot;.   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&#39;s always a backdoor.</div>