<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"><<a href="mailto:cce@ccs.neu.edu" target="_blank">cce@ccs.neu.edu</a>></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 >>> and &&&, 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 &&& and >>> into parameter values; set them differently on two different calls.<br><br></div>3. If &&& and >>> 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's probably more trouble than it's worth. Also, unless "interp" is likely to be nested, simply expanding twice is unlikely to cause a significant problem. Sometimes it'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"><<a href="mailto:neil.toronto@gmail.com" target="_blank">neil.toronto@gmail.com</a>></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'm implementing the semantics using macros; e.g.<br>
<br>
#'(interp (+ 4 5)) => #'(((const 4) . &&& . (const 5)) . >>> . add)<br>
<br>
where `interp' is a macro and `=>' means macro expansion.<br>
<br>
Here's the tricky part. I have to interpret the language using *both* combinator libraries, not just one; e.g. I need #'(interp (+ 4 5)) to expand to both of these:<br>
<br>
#'(((const/bot 4) . &&&/bot . (const/bot 5)) . >>>/bot . add/bot)<br>
#'(((const/pre 4) . &&&/pre . (const/pre 5)) . >>>/pre . add/pre)<br>
<br>
I could have #'(interp (+ 4 5)) expand to something like<br>
<br>
#'(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'm moving the "interpret the language two ways" job into the macro system and hoping it's nicer. It should also generate faster code, and possibly allow type checking on one of the interpretations.)<br>
<br>
The best idea I've had so far is to have (interp e) expand to uses of generic `&&&' and `>>>' combinators, apply `local-expand', and do a syntax tree search-and-replace that does #'&&& => #'&&&/bot, etc. Is there another way, though, that doesn'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 <<a href="mailto:jay@cs.byu.edu" target="_blank">jay@cs.byu.edu</a>><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>"The glory of God is Intelligence" - D&C 93
</div>