[erlang-questions] How to wrap a function of any arity

Ludovic Coquelle lcoquelle@REDACTED
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:
compute_one/1
compute_two/2
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
>    end.
>
> t
>
> On 11/17/06, Ludovic Coquelle <lcoquelle@REDACTED> wrote:
> > I would like to wrap a function into another which send the the result
> of
> > 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
> above
> > 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...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20061118/e3bddc04/attachment.htm>


More information about the erlang-questions mailing list