[erlang-questions] How to wrap a function of any arity
Fri Nov 17 17:24:23 CET 2006
Sorry I did not give a good explanation of what I try to do. I would like to
write the function "wrap_fun" so that I can call it with different inner
functions. Let say I have different functions:
I would like to be able to write:
Log_compute_one = wrap_fun(compute_one, logger),
Log_compute_two = wrap_fun(compute_two, logger).
On 11/18/06, t ty <tty.erlang@REDACTED> wrote:
> Unfortunately I'm not very sure what you need. You can always encode
> all the params into a list also funs can also take multi params
> wrap_fun(Fun, Pid) ->
> fun(One, Two, Three) ->
> Res = Fun(One, Two, Three)
> Pid ! Res
> On 11/17/06, Ludovic Coquelle <lcoquelle@REDACTED> wrote:
> > I would like to wrap a function into another which send the the result
> > the inner function to some external process.
> > Let say I have a function called "compute" and a log process "logger": I
> > want to create a new function with something like:
> > Log_compute = wrap_fun(compute, logger).
> > wrap_fun(Fun, Pid) ->
> > fun(AllArgs) ->
> > Res = Fun(AllArgs),
> > Pid ! Res
> > end.
> > But I don't know how to do that with a function of any arity (the code
> > work only for function of arity 1).
> > Is this do-able? if not, how should I do?
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://www.erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions