[erlang-questions] module reloading
Per Hedeland
per@REDACTED
Wed Apr 18 08:28:33 CEST 2018
On 2018-04-18 08:05, Per Hedeland wrote:
> On 2018-04-18 03:27, Fernando Benavides wrote:
>>
>> Also... Just trying to evaluate _any_ function, loads the module. That's why instead of loading modules manually, when in the shell, I tend to write the module name and :, press tab, if nothing pops
>> up, I type x(). and press enter.
>
> I tend to do the same, even down to the "arbitrary function name", but
> it *is* rather quirky, and there is a hint for an obvious and probably
> straightforward-to-implement (I haven't looked at the relevant code)
> enhancement in your description: why not have the sequence <name>:<TAB>
> do a code:ensure_loaded(<name>) before it (tries to) look up the
> function list?
OK, so I looked at the code, and the change (see below) is so trivial
that there is probably a good reason it doesn't already do that - I
don't know what that reason might be though...
--Per
diff --git a/lib/stdlib/src/edlin_expand.erl b/lib/stdlib/src/edlin_expand.erl
index bdcefda..4b3e0cc 100644
--- a/lib/stdlib/src/edlin_expand.erl
+++ b/lib/stdlib/src/edlin_expand.erl
@@ -49,8 +49,8 @@ expand_module_name(Prefix) ->
expand_function_name(ModStr, FuncPrefix) ->
case to_atom(ModStr) of
{ok, Mod} ->
- case erlang:module_loaded(Mod) of
- true ->
+ case code:ensure_loaded(Mod) of
+ {module, Mod} ->
L = Mod:module_info(),
case lists:keyfind(exports, 1, L) of
{_, Exports} ->
@@ -58,7 +58,7 @@ expand_function_name(ModStr, FuncPrefix) ->
_ ->
{no, [], []}
end;
- false ->
+ {error, _What} ->
{no, [], []}
end;
error ->
More information about the erlang-questions
mailing list