[erlang-questions] serializing functions

Matthias Lang <>
Sun Nov 16 23:10:54 CET 2008


On Monday, November 17, damien morton wrote:
> If I take the most basic of functions, e.g. fun()->0 end. and serialize it
> using term_to_binary(), it seems that this function is serialized to 650
> bytes.

I'd guess you concluded that after trying it in the shell, not a
module. IIRC, funs made in the shell are special, they carry around
a complete (?) representation of the fun.

> I guess I was wondering if its better to send a Mod:Fun pair from one node
> to another, or to send an actual function() object. 

In general, sending the module and the function name is not equivalent
to sending a fun.

> Now, I am still not sure if a function() can be sent over the wire,
> but a Mod:Fun pair sure is a whole lot more compact.

> What are the normal best practices when handling functions that might be
> send over the wire? Prefer Mod:Fun over function()?

The gotchas I can think of are related to code loading.

Matt



More information about the erlang-questions mailing list