[wg-camlp4] Meta Programming from the view of the implementaion

Alain Frisch alain.frisch at lexifi.com
Thu Jan 31 13:32:08 GMT 2013


On 01/31/2013 02:07 PM, Hongbo Zhang wrote:
> For any nontrivial Ast Rewriter, I totally get lost, maybe I am dumb and
> you use objects here(ast_mapper) suppose both ast_mapper try to inject
> some bindings at the beginning, what do you expect here? Besides,
> there's no reason that Ast Rewriter should be pure, once is impure, how
> shall I reason the program?

As soon as you use OCaml code to specify some actions on the AST, you 
have potential problems with impure code.  ppx does not change anything, 
except maybe that each ppx rewriter in run in a separate process, which 
limits the risk of bad interaction between them.

To reason about two ppx rewriters both trying to inject code at the 
beginning, this is easy, just think in terms of functions.  The first 
transformer to be applied adds code to the beginning.  The second one 
adds more code to the beginning.  At the end, the code starts by the 
prefix added by the second ppx rewriter, then the prefix added by the 
first one, then the rest of the code.

> But we do
> have a lot of things that Ast Rewriter does not provide,

Agreed!

> This is *already implemented in Fan within tens of lines of code,* you
> are much more experienced than me, so I bet you definitely could parse
> it! (I don't consider tens of lines of code is complex.. ) my taste
> shows that its notation is much more elegant than sedlex (imho)

I strongly suspect you don't use the official OCaml parser but a 
specific parser which is part of Fan (and rely on a different parsing 
technology and a different AST).  So if I want to use your version of 
sedlex, I will add to update Fan to match my local extensions of OCaml 
(or MetaOCaml, or the next cool extension of Camlp4).  And if I wanted 
to be able to implement that version, I would have had to learn about 
Fan, its parsing technology, and its interpretation of the OCaml AST.
All that would be worth the extra effort and trouble if the benefits 
were clear enough, but I still don't see any benefit.

Alain


More information about the wg-camlp4 mailing list