[erlang-questions] idea: Erlang FFI: callbacks and memory management

Robert Virding <>
Tue Dec 11 23:58:21 CET 2007


On 11/12/2007, Alceste Scalas <> wrote:
>
> Il giorno mar, 11/12/2007 alle 13.33 +0100, Kenneth Lundin ha scritto:
> > Many C-API's have callback functions. It would be nice if that could
> > be handled as well but i am not sure if we can find a generic solution
> > for that.
>
> If there is some way to call an Erlang fun() from C (i.e. from a BIF),
> then the problem should be mostly solved: libffi allows to define
> "closures", i.e. to dynamically create a native function that wraps a
> callback written in the host language.
>
> I briefly mentioned this possibility some months ago, with examples like
> using a C numeric library to integrate a differential equation written
> in Erlang.
>
> However, I was not able to find a way to call a fun() from C.  Maybe I
> completely missed it: if it's the case, a pointer to the relevant
> Erlang/OTP source code would be really helpful...


Callbacks! CALLBACKS! Callbacks are the curse of the programming class. They
should be avoided at all costs.

If you have a callback how do you intend to get data in and out of them?
Callbacks can't live without shared data. In which process are they to be
evaluated? Everything in Erlang exists within a process.

No, the only workable Erlang way is to replace them with messages.

Good grief,

Robert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20071211/ba418d03/attachment.html>


More information about the erlang-questions mailing list