3
提問:我是喬·阿姆斯特朗(務實書架)閱讀編程二郎。在第16章的name_server.erl源代碼中,Dict變量來自哪裏?調用字典:new()會自動生成字典?並且,引用說dict:new()創建字典。我不需要將它存儲爲像Dict = dict:new()?新手對Erlang的字典
-module(name_server).
-export([init/0, add/2, whereis/1, handle/2]).
-import(server1, [rpc/2]).
add(Name, Place) ->
rpc(name_server, {add, Name, Place}).
whereis(Name) ->
rpc(name_server, {whereis, Name}).
init() ->
dict:new().
handle({add, Name, Place}, Dict) ->
{ok, dict:store(Name, Place, Dict)};
handle({whereis, Name}, Dict) ->
{dict:find(Name, Dict), Dict}.