<div dir="ltr">4. Use syntax-parse with attributes that do both expansions at the same time. The automata library does this: <a href="https://github.com/plt/racket/blob/master/pkgs/unstable-pkgs/unstable-lib/automata/re-compile.rkt">https://github.com/plt/racket/blob/master/pkgs/unstable-pkgs/unstable-lib/automata/re-compile.rkt</a><div>
<br></div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Sep 4, 2013 at 3:40 PM, Carl Eastlund <span dir="ltr">&lt;<a href="mailto:cce@ccs.neu.edu" target="_blank">cce@ccs.neu.edu</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>I see three options, off the top of my head:<br><br></div>1. Expand into a lambda that takes the different functions, such as &gt;&gt;&gt; and &amp;&amp;&amp;, as arguments; then apply that function in one place to the /pre variants and in another place to the /bot variants.<br>


<br></div>2. Expand into one expression, and make &amp;&amp;&amp; and &gt;&gt;&gt; into parameter values; set them differently on two different calls.<br><br></div>3. If &amp;&amp;&amp; and &gt;&gt;&gt; need to be macros themselves for some reason, then you may really have two different interpretations here that must be expanded separately.  Sometimes you just have to do work twice.  Although you may be able to save yourself some of that with judicious local-expansion... but that&#39;s probably more trouble than it&#39;s worth.  Also, unless &quot;interp&quot; is likely to be nested, simply expanding twice is unlikely to cause a significant problem.  Sometimes it&#39;s okay to have a single, limited source of macro duplication.<span class="HOEnZb"><font color="#888888"><br>


</font></span></div><div class="gmail_extra"><span class="HOEnZb"><font color="#888888"><br clear="all"><div>Carl Eastlund</div></font></span><div><div class="h5">
<br><br><div class="gmail_quote">On Wed, Sep 4, 2013 at 5:31 PM, Neil Toronto <span dir="ltr">&lt;<a href="mailto:neil.toronto@gmail.com" target="_blank">neil.toronto@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


I have two libraries of combinators meant to be used as targets for a language semantics. I&#39;m implementing the semantics using macros; e.g.<br>
<br>
   #&#39;(interp (+ 4 5))  =&gt;  #&#39;(((const 4) . &amp;&amp;&amp; . (const 5)) . &gt;&gt;&gt; . add)<br>
<br>
where `interp&#39; is a macro and `=&gt;&#39; means macro expansion.<br>
<br>
Here&#39;s the tricky part. I have to interpret the language using *both* combinator libraries, not just one; e.g. I need #&#39;(interp (+ 4 5)) to expand to both of these:<br>
<br>
  #&#39;(((const/bot 4) . &amp;&amp;&amp;/bot . (const/bot 5)) . &gt;&gt;&gt;/bot . add/bot)<br>
  #&#39;(((const/pre 4) . &amp;&amp;&amp;/pre . (const/pre 5)) . &gt;&gt;&gt;/pre . add/pre)<br>
<br>
I could have #&#39;(interp (+ 4 5)) expand to something like<br>
<br>
  #&#39;(list (interp/bot (+ 4 5)) (interp/pre (+ 4 5)))<br>
<br>
But expanding twice is terrible manners when the expression contains macros.<br>
<br>
(Originally, I had super-combinators that did the job of both */bot and */pre combinators. These super-combinators were complicated and messy, especially when used in recursion, which is why I&#39;m moving the &quot;interpret the language two ways&quot; job into the macro system and hoping it&#39;s nicer. It should also generate faster code, and possibly allow type checking on one of the interpretations.)<br>



<br>
The best idea I&#39;ve had so far is to have (interp e) expand to uses of generic `&amp;&amp;&amp;&#39; and `&gt;&gt;&gt;&#39; combinators, apply `local-expand&#39;, and do a syntax tree search-and-replace that does #&#39;&amp;&amp;&amp; =&gt; #&#39;&amp;&amp;&amp;/bot, etc. Is there another way, though, that doesn&#39;t run afoul of macro security?<br>



<br>
Neil ⊥<br>
____________________<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>
</blockquote></div><br></div></div></div>
<br>____________________<br>
  Racket Users list:<br>
  <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>Jay McCarthy &lt;<a href="mailto:jay@cs.byu.edu" target="_blank">jay@cs.byu.edu</a>&gt;<br>Assistant Professor / Brigham Young University<br><a href="http://faculty.cs.byu.edu/~jay" target="_blank">http://faculty.cs.byu.edu/~jay</a><br>
<br>&quot;The glory of God is Intelligence&quot; - D&amp;C 93
</div>