Hi I’ve been using rfc4627 for erlang now ive had this slice of code working before but now after ive made changes to the way things are passed i get a Error in process * on node ‘@127.0.0.1’ with exit value: {{badmatch,{obj,[{c,1}]}}
Here is the code
-define(TO_SELF, fun(S, M, T) -> Msg = {obj, M}, ?LOG("OUTGOING: ~p~n", [Msg]), ok end).
where M is Msg=[{c,1}],
does anyone have any idea what can be causing it ive been trying all day with no luck.
Thanks
Dave
It is probably the variable scoping rules of funs in Erlang which is causing your problem. Any free variables in the fun body which have been bound before the fun is defined will have their value imported into the fun. The fun is a closure so this is common to most languages with closures, it is in fact one of the things which make funs/closures so powerful.
So if
Msgis already bound when you define the fun,its value is then imported and
Msg = {obj,M}does not bindMsgbut tests against it value,fooin the example.