<div dir="ltr"><div class="gmail_extra">There should in most cases be no overhead using merl compared to using erl_syntax directly. In particular, whatever code you _generate_ using merl will be no different from what you would construct through calls to erl_syntax. If there is any overhead, it will be during code generation. You can inspect the Erlang code that merl creates by using erlc +"'P'" (note the extra quotes) or calling compile:file(foo, ['P']).<br clear="all"><div><div class="gmail_signature"><br>        /Richard</div></div>
<br><div class="gmail_quote">On Wed, Jul 15, 2015 at 12:23 AM, Humberto Rodriguez <span dir="ltr"><<a href="mailto:humbert.rguez@gmail.com" target="_blank">humbert.rguez@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Richard, thanks for the example!<div><br></div><div>I have another question: How much is the penalty (performance) of use this way? I am thinking use erlang as base language to make a DSL on top of Riak KV.</div><div><br></div><div>Do you have some advice for me? What is the way that you recommend me, merl or erl_syntax?</div><div><br><div>Best regards,</div><div>--- Humberto<div><div class="h5"><div><br><br>

</div>
<br><div><blockquote type="cite"><div>On 15 Jul 2015, at 00:02, Richard Carlsson <<a href="mailto:carlsson.richard@gmail.com" target="_blank">carlsson.richard@gmail.com</a>> wrote:</div><br><div><div dir="ltr"><div>This is a good opportunity to demonstrate the function erl_syntax:meta/1 (using merl in OTP 18 to simplify building the AST):<br><br></div><div>1> AST=merl:quote("-import(mymdule, [test1/0, test2/0])").</div><div>2> io:put_chars(erl_prettypr:format(erl_syntax:meta(AST))).<br><br>erl_syntax:make_tree(prefix_expr,<br>                     [[erl_syntax:operator('-')],<br>                      [erl_syntax:make_tree(application,<br>                                            [[erl_syntax:atom(import)],<br>                                             [erl_syntax:atom(mymdule),<br>                                              erl_syntax:list([erl_syntax:make_tree(infix_expr,<br>                                                                                    [[erl_syntax:atom(test1)],<br>                                                                                     [erl_syntax:operator('/')],<br>                                                                                     [erl_syntax:integer(0)]]),<br>                                                               erl_syntax:make_tree(infix_expr,<br>                                                                                    [[erl_syntax:atom(test2)],<br>                                                                                     [erl_syntax:operator('/')],<br>                                                                                     [erl_syntax:integer(0)]])])]])]])<br><br></div><div>There's also the useful function merl:show/1 for inspecting the basic structure of an AST:<br><br>3> merl:show(AST).<br><br>prefix_expr: -import(mymdule, [...])<br>  operator: -<br>  +<br>  application: import(mymdule, [test1 / 0, test2 / 0])<br>    atom: import<br>    +<br>    atom: mymdule<br>    list: [test1 / 0, test2 / 0]<br>      infix_expr: test1 / 0<br>        atom: test1<br>        +<br>        operator: /<br>        +<br>        integer: 0<br>      infix_expr: test2 / 0<br>        atom: test2<br>        +<br>        operator: /<br>        +<br>        integer: 0<br><br></div><div><br>    /Richard</div><div class="gmail_extra">
<br><div class="gmail_quote">On Tue, Jul 14, 2015 at 3:08 PM, Humberto Rodríguez Avila <span dir="ltr"><<a href="mailto:h87rguez@gmail.com" target="_blank">h87rguez@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><span style="font-family:Helvetica;font-size:12px">Hello guys!</span><div style="font-family:Helvetica;font-size:12px"><br></div><div style="font-family:Helvetica;font-size:12px">  I am a new programming in Erlang and I interested in doing things with meta-programming. I have been working with merl and I did a couple of examples (module generation). Nevertheless, I have been trying to do the same thing using erl_syntax, but I can’t found how to <span>build</span> the <span>syntax tree</span> of the directive -<span>import</span> :(</div><div style="font-family:Helvetica;font-size:12px"><br></div><div style="font-family:Helvetica;font-size:12px">For example: <span> -import(mymdule, [test1/0, test2/0])</span></div><div style="font-family:Helvetica;font-size:12px"><br></div><div style="font-family:Helvetica;font-size:12px">Any suggestion?</div><div style="font-family:Helvetica;font-size:12px"><br></div><div style="font-family:Helvetica;font-size:12px">Thanks in advance!</div><span><font color="#888888"><div style="font-family:Helvetica;font-size:12px"><br><div>--- Humberto</div></div></font></span></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div></div>
</div></blockquote></div><br></div></div></div></div></div></blockquote></div><br></div></div>