Funs
Rudolph van Graan
rvg@REDACTED
Wed Sep 14 12:11:54 CEST 2005
Hi all,
I've just found a feature (?) that I would like to understand a bit
better.
Make a fun and stick it into ETS:
_TID = ets:new(test,[named_table,public,set]),
F = fun(Name) ->
io:format("Name = ~p\n",[Name])
end,
ets:insert(test,{f,F});
Retrieve and run it:
[{f,F}] = ets:lookup(test,f),
F(Name).
>null:test("asdasd").
Name = "asdasd"
ok
Change the fun
F = fun(Name) ->
io:format("Name = ~p\n",[Name ++ "asdasd"])
end,
Recompile
Run the fun from ETS again:
** exited: {{badfun,#Fun<null.0.423762>},
[{null,test,1},
{erl_eval,do_apply,5},
{shell,exprs,6},
{shell,eval_loop,3}]} **
I only changed the code IN the fun, not any references or arity or
anything else. I presume beam checks the version of the stored fun
against the one in ets and gives me a badfun when they don't match.
Is there any way to relax this checking to only look at:
1. Arity and
2. That the number of external references stay the same and
3. The fun is still in the same location in the code (i.e. index etc)
The problem has to do with dynamic code upgrade and although I can
guarantee that the funs behave the same, I cannot guarantee the
version numbers nor have I control over it. Ideas?
Rgds,
Rudolph
More information about the erlang-questions
mailing list