<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br></div><div>If the code you want to pretty-print is generated from other code - and you don't want to create abstract forms by hand (most don't) - I can also recommend parse_trans_codegen:</div><div><br></div><div><a href="https://github.com/esl/parse_trans/blob/master/doc/parse_trans_codegen.md">https://github.com/esl/parse_trans/blob/master/doc/parse_trans_codegen.md</a></div><div><br></div><div>It's a fairly easy, and less error-prone, way to generate code.</div><div><br></div><div>If you look e.g. at <a href="https://github.com/esl/parse_trans/blob/master/examples/ex_codegen.erl">https://github.com/esl/parse_trans/blob/master/examples/ex_codegen.erl</a></div><div><br></div><div>we can try the two first functions:</div><div><br></div><div><div>f(Name) -></div><div>    codegen:gen_function(</div><div>      Name,</div><div>      fun(1,2,3) -></div><div>              foo;</div><div>          (A,B,C) -></div><div>              {A,B,C}</div><div>      end).</div><div><br></div><div>g(Name, V) -></div><div>    codegen:gen_function(</div><div>      Name,</div><div>      fun(L) -></div><div>              member({'$var',V}, L)</div><div>      end).</div></div><div><br></div><div><br></div><div><div>Eshell V5.9  (abort with ^G)</div><div>1> c(ex_codegen).</div><div>{ok,ex_codegen}</div><div>2> ex_codegen:f(foo).</div><div>{function,9,foo,3,</div><div>          [{clause,11,</div><div>                   [{integer,11,1},{integer,11,2},{integer,11,3}],</div><div>                   [],</div><div>                   [{atom,12,foo}]},</div><div>           {clause,13,</div><div>                   [{var,13,'A'},{var,13,'B'},{var,13,'C'}],</div><div>                   [],</div><div>                   [{tuple,14,[{var,14,'A'},{var,14,'B'},{var,14,'C'}]}]}]}</div><div>3> ex_codegen:g(is_in, foo).</div><div>{function,20,is_in,1,</div><div>          [{clause,22,</div><div>                   [{var,22,'L'}],</div><div>                   [],</div><div>                   [{call,23,{atom,23,member},[{atom,23,foo},{var,23,'L'}]}]}]}</div></div><div><div>4> io:fwrite("~s~n", [erl_pp:form(v(3))]).</div><div>is_in(L) -></div><div>    member(foo, L).</div></div><div><br></div><div><br></div><div>…you get the idea.</div><div><br></div><div>Now, since I actually don't know exactly what you are trying to do, I will quit throwing out suggestions. :)</div><div><br></div><div>BR,</div><div>Ulf W</div><br><div><div>On 11 May 2012, at 22:28, Roberto Ostinelli wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Thank you Ulf.</div><div><br></div><div>So i first should erl_parse:tokens/1, then erl_parse:parse/form/1 then use what you suggested?</div><br><br><div class="gmail_quote">On Fri, May 11, 2012 at 1:09 PM, Ulf Wiger <span dir="ltr"><<a href="mailto:ulf@feuerlabs.com" target="_blank">ulf@feuerlabs.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"><div><br></div><div>You could take a look at how parse_trans does it:</div><div><br></div>
<div><a href="https://github.com/esl/parse_trans/blob/master/src/parse_trans_pp.erl#L65" target="_blank">https://github.com/esl/parse_trans/blob/master/src/parse_trans_pp.erl#L65</a></div><div><br></div><div>It uses erl_pp instead of erl_prettypr for reasons I have since forgotten</div>
<div>(it was something that, at one time, erl_prettypr had problems with, but</div><div>erl_pp was able to handle).</div><div><br></div><div>BR,</div><div>Ulf W</div><br><div><div><div class="h5"><div>On 11 May 2012, at 22:01, Roberto Ostinelli wrote:</div>
<br></div></div><blockquote type="cite"><div><div class="h5">Dear All,<div><br></div><div>is there a way to use prettypr on a list()?</div><div><br></div><div>I want to pretty format some source code, all I found is a Trapexit post showing this:</div>
<div><br></div><div><span style="font-family:'Trebuchet MS','Lucida Grande',Verdana,Arial,sans-serif;font-size:13px;line-height:16px;text-align:left;background-color:rgb(243,243,243)">F="tst.erl",</span></div>

<div><span style="font-family:'Trebuchet MS','Lucida Grande',Verdana,Arial,sans-serif;font-size:13px;line-height:16px;text-align:left;background-color:rgb(243,243,243)">erl_prettypr:format(erl_recomment:recomment_forms(element(2,epp_dodger:parse_file(F)),erl_comment_scan:file(F))).</span><br style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-family:'Trebuchet MS','Lucida Grande',Verdana,Arial,sans-serif;font-size:13px;line-height:16px;text-align:left;background-color:rgb(243,243,243)">

</div><div style="text-align:left"><font face="'Trebuchet MS', 'Lucida Grande', Verdana, Arial, sans-serif"><span style="line-height:16px"><br></span></font></div><div style="text-align:left"><span style="text-align:-webkit-auto">Unfortunately this is based on parsing a file, and epp_dodger needs an IoDevice to parse code.</span></div>

<div style="text-align:left"><span style="text-align:-webkit-auto"><br></span></div><div style="text-align:left"><span style="text-align:-webkit-auto">Is there a way to do something similar but inputting the code as list() instead of parsing a file?</span></div>

<div style="text-align:left"><span style="text-align:-webkit-auto"><br></span></div><div style="text-align:left"><span style="text-align:-webkit-auto">r.</span></div></div></div>
_______________________________________________<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" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div><br><div>
<div><div>Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.</div><div><a href="http://feuerlabs.com/" target="_blank">http://feuerlabs.com</a></div></div><div><br></div><br>
</div>
<br></div></blockquote></div><br>
</blockquote></div><br><div apple-content-edited="true">
<div><div>Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.</div><div><a href="http://feuerlabs.com">http://feuerlabs.com</a></div></div><div><br></div><br class="Apple-interchange-newline">
</div>
<br></body></html>