我的Erlang编程技巧大全

这里集中记录我的Erlang编程过程中零散发现的小的技巧以及代码之类的
防止被不良网站抓取,先不写具体内容,过几天再来补上

防止被不良网站抓取,先不写具体内容,过几天再来补上

#### 方便debug的macro定义 #### 2010-11-06
#### 一个函数加载所有的重新编译的代码 #### 2010-10-23
经常,会改变一个代码,逐个l(module)的话,很麻烦,一个lm()全搞定

lm() ->
[c:l(M) || M <- mm()].

mm() ->
modified_modules().

modified_modules() ->
[M || {M, _} <- code:all_loaded(),
module_modified(M) == true].

module_modified(Module) ->
case code:is_loaded(Module) of
{file, preloaded} ->
false;
{file, Path} ->
CompileOpts =
proplists:get_value(compile, Module:module_info()),
CompileTime = proplists:get_value(time, CompileOpts),
Src = proplists:get_value(source, CompileOpts),
module_modified(Path, CompileTime, Src);
_ ->
false
end.

module_modified(Path, PrevCompileTime, PrevSrc) ->
case find_module_file(Path) of
false ->
false;
ModPath ->
case beam_lib:chunks(ModPath, ["CInf"]) of
{ok, {_, [{_, CB}]}} ->
CompileOpts = binary_to_term(CB),
CompileTime = proplists:get_value(time,
CompileOpts),
Src = proplists:get_value(source, CompileOpts),
not (CompileTime == PrevCompileTime) and
(Src == PrevSrc);
_ ->
false
end
end.

find_module_file(Path) ->
case file:read_file_info(Path) of
{ok, _} ->
Path;
_ ->
%% may be the path was changed
case code:where_is_file(filename:basename(Path)) of
non_existing ->
false;
NewPath ->
NewPath
end
end.



#### 方便debug的macro定义 #### 2010-11-06

-define(x(X), io:format("~p~p: ~s = ~p~n", [?MODULE, ?LINE, ??X, X])).

test() ->
VeryLongVariableName = foo(),
?x(VeryLongVariableName).
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值