[erlang-questions] Execute module code from stored anonymous function

Pierre Fenoll <>
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!



Cheers,
-- 
Pierre Fenoll


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
>>> 
>>> http://erlang.org/mailman/listinfo/erlang-questions
>>>
>>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160911/f19b214d/attachment.html>


More information about the erlang-questions mailing list