I read Joe Armstrong's "Programming Erlang" (Pragmatic Bookshelf). In the source code name_server.erl in chapter 16, where is the Dict variable ? Calling dict: new () automatically generates a dict? And, it is referenced that dict: new () creates a dictionary. Is it necessary to store it as a variable of type Dict = dict: new () ?
-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}.
source
share