Finishing up part 1.
This commit is contained in:
parent
2796f1b209
commit
d88b7f8bcf
|
@ -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.
|
|
@ -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))).
|
||||
|
||||
|
Loading…
Reference in New Issue