<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On 25 Dec 2014, at 11:55, Dror Mein <<a href="mailto:drormein@yahoo.com">drormein@yahoo.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div id="yui_3_16_0_1_1419501643512_2424" dir="ltr" class="" style="font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">My preferred solution would be somehow to compile a function turning it into <erl_eval> in a module. Is it possible? will it work?</div><br class="Apple-interchange-newline"></blockquote></div><div><br></div><div>One solution to this can be found in the locks application:</div><div><br></div><div><a href="https://github.com/uwiger/locks/blob/master/src/locks_watcher.erl">https://github.com/uwiger/locks/blob/master/src/locks_watcher.erl</a></div><div><br></div><div>The code is invoked via a parse transform:</div><div><a href="https://github.com/uwiger/locks/blob/master/src/locks_agent.erl#L39">https://github.com/uwiger/locks/blob/master/src/locks_agent.erl#L39</a></div><div><br></div><div>And the transform expands the pseudo-call `locks_watcher(self())`</div><div><a href="https://github.com/uwiger/locks/blob/master/src/locks_agent.erl#L731">https://github.com/uwiger/locks/blob/master/src/locks_agent.erl#L731</a></div><div><br></div><div><br>watch_node(N) -><br>    {M, F, A} =<br>        locks_watcher(self()),  % expanded through parse_transform<br>    P = spawn(N, M, F, A),<br>    erlang:monitor(process, P).</div><div><br></div><div>The {M, F, A} tuple will be {erl_eval, exprs, [Exprs, Bindings]}, where</div><div>Exprs is the abstract-form representation of the code for</div><div>locks_watcher:locks_watcher/1.</div><div><br></div><div>Another version can be found in the deqc application:</div><div><a href="https://github.com/uwiger/deqc/blob/master/src/deqc_proxy.erl#L80">https://github.com/uwiger/deqc/blob/master/src/deqc_proxy.erl#L80</a></div><div><br></div><div>where the function disconnect_script(Node) ends up returning a list of abstract forms via some parse transform magic.</div><div><br></div><div><br>disconnect_script(EqcNode) -><br>    codegen:exprs(<br>      fun() -><br><span class="Apple-tab-span" style="white-space:pre">       </span>      Nodes = nodes(),<br><span class="Apple-tab-span" style="white-space:pre">   </span>      [net_kernel:disconnect(N) || N <- Nodes -- [{'$var', EqcNode}]]<br>      end).</div><div><br></div><div>The function codegen:exprs/1 is a pseudo function handled by parse_trans_codegen.</div><div><br></div><div>BR,</div><div>Ulf W</div><br><div apple-content-edited="true">
<span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px;"><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></span><br class="Apple-interchange-newline">

</div>
<br></body></html>