MD5 未在 erlang 模块的模块信息中更新

MD5 is not getting updated in Module info of erlang module

仅供参考:我刚刚在 https://learnyousomeerlang.com 的帮助下开始学习 Erlang。

在阅读有关 module_info 的章节时。以下是我为其中一个模块获得的输出。

[{module,useless},
 {exports,[{add,2},
           {hello,0},
           {greet_and_add_two,1},
           {module_info,0},
           {module_info,1}]},
 {attributes,[{vsn,[296174539721071843666185210011547328263]},
              {author,"An Erlang Champ"}]},
 {compile,[{version,"7.4"},
           {options,[debug_info,export_all]},
           {source,"/Users/vivekdhayalan/useless.erl"}]},
 {native,false},
 {md5,<<222,209,36,56,31,223,59,231,71,237,66,109,149,39,
        223,7>>}]

我注意到我的输出中有 md5 属性,出于好奇我更新了我的模块并再次按模块编译后检查了模块信息。但是,我仍然发现了相同的 md5,想着可能是什么原因。

如有线索请帮忙了解。可能是我对 md5 感到好奇,因为我还没有完成本章。

注意:vsn 也没有更新

更新更多信息。

我的初始代码:

-module(useless).
-export([add/2, hello/0, greet_and_add_two/1]).

add(C,B) ->
C + B.

%% Shows greetings.
%% io:format/1 is the standard function used to output text.
hello() ->
io:format("Hello, world!~n").

greet_and_add_two(X) ->
hello(),
add(X,2).

模块信息和编译步骤

28> compile:file(useless, [debug_info, export_all]).
{ok,useless}
29> useless:module_info().                          
[{module,useless},
 {exports,[{add,2},
           {hello,0},
           {greet_and_add_two,1},
           {module_info,0},
           {module_info,1}]},
 {attributes,[{vsn,[296174539721071843666185210011547328263]},
              {author,"An Erlang Champ"}]},
 {compile,[{version,"7.4"},
           {options,[debug_info,export_all]},
           {source,"/Users/vivekdhayalan/useless.erl"}]},
 {native,false},
 {md5,<<222,209,36,56,31,223,59,231,71,237,66,109,149,39,
        223,7>>}]

我正在通过添加作者来更新我的模块,如下所示

-module(useless).
-export([add/2, hello/0, greet_and_add_two/1]).
-author("An Erlang Champ").

add(C,B) ->
C + B.

%% Shows greetings.
%% io:format/1 is the standard function used to output text.
hello() ->
io:format("Hello, world!~n").

greet_and_add_two(X) ->
hello(),
add(X,2).

编译后我的模块信息。

compile:file(useless, [debug_info, export_all]).
{ok,useless}
31> useless:module_info().                          
[{module,useless},
 {exports,[{add,2},
           {hello,0},
           {greet_and_add_two,1},
           {module_info,0},
           {module_info,1}]},
 {attributes,[{vsn,[296174539721071843666185210011547328263]},
              {author,"An Erlang Champ"}]},
 {compile,[{version,"7.4"},
           {options,[debug_info,export_all]},
           {source,"/Users/vivekdhayalan/useless.erl"}]},
 {native,false},
 {md5,<<222,209,36,56,31,223,59,231,71,237,66,109,149,39,
        223,7>>}]

我们可以看到 md5 即使在添加信息后也没有更新。

-module(my).
-compile([export_all]).

go() -> "hello".

在shell中:

~/erlang_programs$ erl
Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V9.3  (abort with ^G)

1> c(my).
my.erl:2: Warning: export_all flag enabled - all functions will be exported
{ok,my}

2> my:module_info().
[{module,my},
 {exports,[{go,0},{module_info,0},{module_info,1}]},
 {attributes,[{vsn,[317460282063015155415500557234702055363]}]},
 {compile,[{options,[]},
           {version,"7.1.5"},
           {source,"/Users/7stud/erlang_programs/my.erl"}]},
 {native,false},
 {md5,<<"îÔ W­ÝÒ\n©¥ëíQ&÷Ã">>}]

添加另一个功能:

-module(my).
-compile([export_all]).

stop() -> "goodbye".
go() -> "hello".

在shell中:

5> c(my).           
my.erl:2: Warning: export_all flag enabled - all functions will be exported
{ok,my}

6> my:module_info().
[{module,my},
 {exports,[{stop,0},
           {go,0},
           {module_info,0},
           {module_info,1}]},
 {attributes,[{vsn,[210928589040636765166954307796272702313]}]},
 {compile,[{options,[]},
           {version,"7.1.5"},
           {source,"/Users/7stud/erlang_programs/my.erl"}]},
 {native,false}, 
 {md5,<<158,175,94,91,0,91,194,106,194,244,45,224,190,48,
        99,105>>}]

I updated my module and checked the module info after compiling by module once again. But, I still found the same md5 thinking what could be the reason.

证明一下。

compile:file() 编译为磁盘上的新 .beam 文件,但不加载它。 module_info() 函数报告加载版本的状态。 shell c() 快捷方式将同时编译和加载 - 使用它代替交互工作。