-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmacro.erl
71 lines (64 loc) · 1.85 KB
/
macro.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
%%%-------------------------------------------------------------------
%%% @author 纪秀峰 <[email protected]>
%%% @doc
%%%
%%% @end
%%% Created : 2012-10-10 15:47 by 纪秀峰 <[email protected]>
%% Last Updated: 纪秀峰 2012-10-12 20:20:59 星期五
%%%-------------------------------------------------------------------
-module(macro).
-export([test/0]).
-define(VERYFY(Value,ErrorId),case Value of false -> throw(ErrorId);true-> ok end) .
-define(CASE(TEST,TRUE,FALSE),case TEST of true->TRUE; false ->FALSE end ).
-define(FE(List,E,Eval),
lists:foreach(
fun(E)->
Eval
end,List
)).
-define(FOLD(List,E,Init,Acc,Eval),
lists:foldl(
fun(E,Acc)->
Eval
end,Init,List
)).
-define(FILTER(List,E,Eval),lists:filter(fun(E)-> Eval end,List)).
-define(TRY(Eval),
try
Eval
catch
throw:{errorid ,ErrorId}->
io:format("handle errorid:~ts~n",[ErrorId]);
%% ResultMsg =pill_packet:encode_pill_error_s2c(ErrorId),
%% role_op:send_data_to_gate(ResultMsg);
_:Msg->
slogger:msg("~p~n",[Msg]),
ok
end
).
test()->
%% io:format("~p~n",[?CASE(1>2 ,1,2)])
?FE([[1,11],[2,22],[3,33]],E,
begin
?FE(E,E2,
begin
io:format("~p,",[E2])
end
),
io:format("~n",[])
end),
Sum=?FOLD([1,2,3],E,0,Acc,
begin
E+Acc
end),
io:format("sum=~p~n",[Sum]),
Num=?FILTER([1,2,3,4],E,
begin
E rem 2 ==1
end),
io:format("filter:~p~n",[Num]) ,
?FILTER([1,2],_E,1==2),
?TRY(begin
?VERYFY(1==2,{errorid,"1!=2"})
end)
.