Ok, that's what I do for now, but it doesn't really fit my need: I do not know the arguments at the time to wrap the function.<br>I wanted to first wrap the function and then apply the resulting wrapped function with different arguments.
<br><br>The idea was to propose an API which get any function from an external module, and transform it (wrap) in another kind of function that I can use in my framework.<br>Anyway, if it is not possible I will revise my design.
<br>Thanks<br><br><div><span class="gmail_quote">On 11/18/06, <b class="gmail_sendername">Ulf Wiger (TN/EAB)</b> <<a href="mailto:ulf.wiger@ericsson.com">ulf.wiger@ericsson.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>
<div><font color="#0000ff" face="Arial" size="2"></font> </div>
<div><span><font color="#0000ff" face="Arial" size="2">Instead of passing the function name, pass a fun:</font></span></div>
<div><span><font color="#0000ff" face="Arial" size="2"></font></span> </div>
<div><span><font color="#0000ff" face="Arial" size="2">Log_compute = wrap_fun(fun() -> compute(AllArgs) end,
logger).</font></span></div>
<div><span><font color="#0000ff" face="Arial" size="2"></font></span> </div>
<div><span><font color="#0000ff" face="Arial" size="2">wrap_fun(Fun, Pid) -></font></span></div>
<div><span><font color="#0000ff" face="Arial" size="2"> Res = Fun(),</font></span></div>
<div><span><font color="#0000ff" face="Arial" size="2"> Pid ! Res.</font></span></div>
<div><span><font color="#0000ff" face="Arial" size="2"></font></span> </div>
<div><span><font color="#0000ff" face="Arial" size="2">The
fun acts as a "closure" and inherits the state from its
surroundings.</font></span></div>
<div><span><font color="#0000ff" face="Arial" size="2">It can
fully encapsulate the data needed, so there is no need for any
</font></span></div>
<div><span><font color="#0000ff" face="Arial" size="2">arguments.</font></span></div>
<div><span><font color="#0000ff" face="Arial" size="2"></font></span> </div>
<div><span><font color="#0000ff" face="Arial" size="2">(The
example now feels a bit contrived, but perhaps you get the point
anyway?)</font></span></div>
<div><span><font color="#0000ff" face="Arial" size="2"></font></span> </div>
<div><span><font color="#0000ff" face="Arial" size="2">BR,</font></span></div>
<div><span><font color="#0000ff" face="Arial" size="2">Ulf
W</font></span></div><br>
<blockquote style="border-left: 2px solid rgb(0, 0, 255); padding-left: 5px; margin-left: 5px; margin-right: 0px;">
<div dir="ltr" align="left" lang="en-us">
<hr>
<font face="Tahoma" size="2"><b>From:</b> <a href="mailto:erlang-questions-bounces@erlang.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">erlang-questions-bounces@erlang.org</a>
[mailto:<a href="mailto:erlang-questions-bounces@erlang.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">erlang-questions-bounces@erlang.org</a>] <b>On Behalf Of </b>Ludovic
Coquelle<br><b>Sent:</b> den 17 november 2006 16:47<br><b>To:</b>
<a href="mailto:erlang-questions@erlang.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">erlang-questions@erlang.org</a><br><b>Subject:</b> [erlang-questions] How to wrap
a function of any arity<br></font><br></div><div><span class="e" id="q_10ef6bc4db51b160_1">
<div></div>I would like to wrap a function into another which send the the
result of the inner function to some external process.<br>Let say I have a
function called "compute" and a log process "logger": I want to create a new
function with something like: <br><br><span style="font-family: courier new,monospace;">Log_compute = wrap_fun(compute,
logger).</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">wrap_fun(Fun, Pid) -></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> fun(AllArgs)
-></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
Res = Fun(AllArgs),</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
Pid ! Res</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
end.</span><br><br>But I don't know how to do that with a function of any
arity (the code above work only for function of arity 1).<br>Is this do-able?
if not, how should I do?<br><br></span></div></blockquote></div>
</blockquote></div><br>