0%

erlang shell下rr使用

  1. rr/1erlang shell下加载record的定义;
  2. rr只能在erlang shell下调用;
  3. 项目中有N多record定义, 需要快速加载所有的定义;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
rr() ->
HrlList = get_hrl_list(),
A = <<"复制下面的代码执行:">>,
io:format("~ts~n", [A]),
io:format("rp([rr(X) || X <- [\"~s\"] ]).~n", [string:join(HrlList, "\",\"")]).

get_hrl_list() ->
{ok, [{DirList, OptList}]} = file:consult("./Emakefile"),
F = fun(Dir, L) ->
WildCard = io_lib:format("~s.hrl", [Dir]),
L ++ filelib:wildcard(WildCard)
end,
F_1 = fun(Opt, L) ->
case Opt of
{i, Include} ->
WildCard = io_lib:format("~s/*.hrl", [Include]),
L ++ filelib:wildcard(WildCard);
_ -> L
end
end,
FileList = lists:foldl(F, [], DirList) ++ lists:foldl(F_1, [], OptList),
FileList.