[erlang-questions] Calling external modules from a fun

David Mercer dmercer@REDACTED
Fri Apr 23 16:09:05 CEST 2010


On Wednesday, April 21, 2010, Alessandro Sivieri wrote:

> I am working on an application which, for some reasons, creates a fun
> (probably something more like a continuation) and then sends it to a
> different node for execution; the sender node is launched with my
> application code path (the ebin directory), and so the receiver one.
> Now, if my code path contains some module which I have wrote, I have found
> that in a fun I cannot invoke it (as module:function), because if I do so,
> the remote machine (which actually receives and executes the fun itself)
> answers with an undefined_lambda error; so my question is: is there a way
> to
> call a function from a fun remotely received, if it is not from the
> standard
> Erlang distribution?

Since no-one smarter than me responded, here's my take.  In order for a fun
to work on a remote node, the module that created the fun must also exist on
the remote node.  I think of funs less as self-contained lambdas, but more
of pointers to the code in the module that created it, along with any bound
values required for the closure.  Thus, if the module is not present on the
remote node (or if it is a different version of the same), I believe the fun
cannot exist on the remote node.  Not sure exactly what happens on the
remote node when it is received -- whether it crashes the node, crashes the
process that receives it, or just crashes any process that tries to execute
it.

Cheers,

DBM



More information about the erlang-questions mailing list