[erlang-questions] Sending funs between nodes

Gaspar Chilingarov nm@REDACTED
Thu Sep 13 21:32:03 CEST 2007


Bengt Kleberg wrote:
> Greetings,
> 
> 
> yes, the fun needs the code.
> yes, you need the beam files on both nodes.
> 


there are 2 ways -- if you define fun inside module (like in your 
example) fun is defined inside module at compile time and is passed 
around as reference to some funcion in that module.

if you compile it from shell (i.e. parsing text form and then compiling 
it to bytecode), then compiler creates full bytecode, not only the 
references -- and these funs are possible to pass between nodes.

Look at term_to_binary(Fun) -- if you get short form (say 12-16 bytes) 
-- it's just reference to the module.

If you get longer one - several hundred bytes -- then it's fun's full body.


/Gaspar





> 
> bengt
> 
> Those were the days...
>     EPO guidelines 1978: "If the contribution to the known art resides
>     solely in a computer program then the subject matter is not
>     patentable in whatever manner it may be presented in the claims."
> 
> 
> On 2007-08-29 21:28, Kirill Zaborski wrote:
>> I was trying to do the following:
>> 1) a module on node X -
>> -------------------
>> -module(test1).
>> -export([go/0]).
>>
>> go() ->
>> P = spawn(fun() -> receive X -> X() end end),
>> register(rrr, P).
>> -------------------
>> 2) a module on node Y -
>> -------------------
>> -module(test2).
>> -export([go/0]).
>>
>> go() ->
>> {rrr, x@REDACTED}!fun() -> io:format("bar",[]) end.
>> -------------------
>>
>> LOKI is my hostname :)
>>
>> So If I run test1:go() and then test2:go() on other node I get
>>
>> =ERROR REPORT==== 29-Aug-2007::22:34:29 ===
>> Error in process <0.35.0> on node 'y@REDACTED' with exit value: 
>> {undef,[{shell_defau
>> lt,fun_to_list,[#Fun<erl_eval.20.62269157>]},{erl_eval,do_apply,5},{shell,exprs,
>> 6},{shell,eval_loop,3}]}
>>
>> ** exited: {undef,[{shell_default,fun_to_list,[#Fun<erl_eval.20.62269157>]},
>>                    {erl_eval,do_apply,5},
>>                    {shell,exprs,6},
>>                    {shell,eval_loop,3}]} **
>>
>> It looks like fun needs code of the module where it was defined. Why is 
>> it so?
>> is there any way around this issue? Or I need the same beams on all the 
>> nodes?
>>
>>
>> Best regards,
>> Kirill Zaborski.
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://www.erlang.org/mailman/listinfo/erlang-questions
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
> 


-- 
Gaspar Chilingarov

System Administrator,
Network security consulting

t +37493 419763 (mob)
i 63174784
e nm@REDACTED
w http://zanazan.am/




More information about the erlang-questions mailing list