Finishing up part 1.

This commit is contained in:
Kyle Isom 2019-04-25 23:02:54 -07:00
parent 2796f1b209
commit d88b7f8bcf
3 changed files with 40 additions and 0 deletions

16
pe/a.erl Normal file
View File

@ -0,0 +1,16 @@
-module(a).
-compile(export_all).
start(Tag) ->
spawn(fun () -> loop(Tag) end).
loop(Tag) ->
sleep(),
Val = b:x(),
io:format("Vsn1 (~p) b:x() = ~p~n", [Tag, Val]).
loop(Tag).
sleep() ->
receive
after 3000 -> true
end.

4
pe/b.erl Normal file
View File

@ -0,0 +1,4 @@
-module(b).
-export([x/0]).
x () -> 1.

20
pe/chapter8.erl Normal file
View File

@ -0,0 +1,20 @@
-module(chapter8).
-export([unique_funs/0]).
%% The command code:all_loaded() returns a list of {Mod,File} pairs of
%% all modules that have been loaded into the Erlang system. Use the
%% BIF Mod:module_info() to find out about these modules. Write
%% functions to determine which module exports the most functions and
%% which function name is the most common. Write a function to find
%% all unambiguous function names, that is, function names that are
%% used in only one module.
unique_funs() ->
unique_funs(code:all_loaded(), sets:new()).
unique_funs([], UniqueFuns) ->
{sets:size(UniqueFuns), sets:to_list(UniqueFuns)};
unique_funs([{Mod, _File}|T], UniqueFuns) ->
Funs = lists:map(fun ({Fun, _Arity}) -> Fun end, Mod:module_info(exports)),
unique_funs(T, sets:union(UniqueFuns, sets:from_list(Funs))).