<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:12pt"><div><span>Shudder ... yeah, this is about what I thought might be the "default case". Are there any principles about what values go with what free variables?</span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;"><span><br></span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;"><span>Best,</span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style:
normal;"><span>Thomas</span></div><div class="yahoo_quoted" style="display: block;"> <br> <br> <div style="font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12pt;"> <div style="font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12pt;"> <div dir="ltr"> <font size="2" face="Arial"> On Tuesday, December 3, 2013 2:02 PM, Richard Carlsson <carlsson.richard@gmail.com> wrote:<br> </font> </div> <blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; margin-top: 5px; padding-left: 5px;"> <div class="y_msg_container">On 2013-12-03 13:14 , Thomas Lindgren wrote:<div class="yqt6980179478" id="yqtfd81053"><br clear="none">> Hi guys,<br clear="none">><br clear="none">> Before I start hacking on something, I thought I'd ask whether there<br clear="none">> already is a standard way to get the original code from a
compiled<br clear="none">> fun/closure. (I know you can get it for interpreted funs by using fun_info.)<br clear="none">><br clear="none">> E.g., for code like this:<br clear="none">><br clear="none">> -module(a).<br clear="none">> -compile(export_all).<br clear="none">> adder(N) -> fun(X) X+N end.<br clear="none">><br clear="none">> I'd like to be able to write something like this:<br clear="none">><br clear="none">> > c(a), F = a:adder(3), magic:get_code(F).<br clear="none">> {fun, 0, [{clause, 0, [{var, 0, 'X'}], [], [{op, '+', {var,<br clear="none">> 0,'X'},{var,0,'N'}}]}], [{'N', 3}]} %% AST of fun F with free var env<br clear="none">><br clear="none">> Or the equivalent.</div><br clear="none"><br clear="none">Use fun_info to get the name/arity of the generated function and dig it <br clear="none">out from the debug_info AST (or for bonus points, reverse-compile the <br
clear="none">beam code)?<br clear="none"><br clear="none">Keep in mind that if the code in the fun contains a local call to a <br clear="none">function in the same module, you'll need to include the code for all <br clear="none">reachable functions as well. Hence, the whole AST or the .beam file as a <br clear="none">binary might be more suitable for whatever it is you're doing.<br clear="none"><br clear="none"> /Richard<div class="yqt6980179478" id="yqtfd77728"><br clear="none"><br clear="none"></div><br><br></div> </blockquote> </div> </div> </div> </div></body></html>