[erlang-questions] Execute module code from stored anonymous function
Sun Sep 11 10:39:06 CEST 2016
> In your case the pointer to function is stored internally and it goes
extinct when module is gone.
Why is this the behavior? I would expect the fun to properly call the
latest version of the module's code if not purged,
throwing an exception otherwise, not "just throw because version changed".
Why disallow funs to directly reference version-changing code?
(indirectly because fun () -> apply(M, F, A) end is still possible)
I am surprised & interested in the reasons behind having
* fun () -> mod:fname(Arg1, Arg2, ...) end
* fun () -> erlang:apply(mod, fname, [Arg1, Arg2, ...]) end
be semantically different!
On 11 September 2016 at 09:27, Nuku Ameyibor <> wrote:
> thanks for quick reply .
> will give it a shot .
> On Sun, Sep 11, 2016 at 7:08 AM, Dmytro Lytovchenko <
> > wrote:
>> In your case the pointer to function is stored internally and it goes
>> extinct when module is gone.
>> If you make it calculate function at runtime by, say, calling
>> apply(mprocess, process_template, [test]), then it should work.
>> sön 11 sep. 2016 kl 08:57 skrev Nuku Ameyibor <>:
>>> Dear List ,
>>> i run into an issue where i was storing an anonymous function in mnesia
>>> to be executed later .
>>> *F=fun(test) ->mprocess:process_template(test)end.*
>>> however as soon as i make some changes to the mprocess module and
>>> upgrade the module i get a *** exception error: bad function* error
>>> when i retrieve the fun and try to execute which i assume is because of the
>>> difference in the module versions .
>>> Is there a way of making the stored fun execute the code and not have
>>> version conflicts .
>>> erlang-questions mailing list
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions