[erlang-questions] Calling external modules from a fun
Scott Lystig Fritchie
Fri Apr 23 20:00:46 CEST 2010
David Mercer <> wrote:
dm> Since no-one smarter than me responded, here's my take.
I don't claim to be any smarter on this subject, but there's some
empirical study possible while we wait for wisdom.
dm> In order for a fun to work on a remote node, the module that created
dm> the fun must also exist on the remote node.
True and false. If you use this syntax, yes, there's a module
spawn(Node, fun some_module:foo_func/0).
There's a noticable difference in the sizes of:
size(term_to_binary(fun() -> some_module:foo_func() end)).
If the fun uses the fun() -> ... end syntax, then any function calls
made externally must be resolvable by the VM, the code server, etc. So
"fun() -> erlang:display(42) end" will work because the BIF definitely
exists over on the remote node ... because it's a BIF.
The same resolvability property can be seen when using intra-module
calls. Using size(term_to_binary(Fun)), we see create experiments that
show that all of the transitively dependent functions are not included
in the fun because the size won't change.
More information about the erlang-questions