Erlang常用関数

7510 ワード

1、消重アルゴリズム:
?
1
2
3
41 > List = [ 1 , 2 , 3 , 1 , 2 , 4 ]. [ 1 , 2 , 3 , 1 , 2 , 4 ] 2 > sets :to_list (sets :from_list (List)). [ 3 , 2 , 1 , 4 ]
2、並べ替えアルゴリズム:
?
1
23 >lists :sort (List). [ 1 , 1 , 2 , 2 , 3 , 4 ]
要素に基づいてソート
?
1
2
3
4
5
6
7
8
9
10
114 >rd(app{id,date,pkg_name,appname,version,user_num,new_user_num,used_num,los,sum_user}). app 5 > Sort = fun ( A , B )-> A #app.date =< B#app.date end.                            #Fun<erl_eval.12.113037538> 6 > lists :sort (Sort, D ).% date [ #app{                              id = {app_id,{ 2010 , 7 , 1 },<< "Packagename" >>},       date = { 2010 , 7 , 1 },       pkg_name = << "Packagename" >>,appname = << "Appname" >>,       version = << "Version" >>,user_num = 1 ,new_user_num = 1 ,       used_num = 1 ,los = 7223 ,sum_user = 2 }... ...
3、並べ替え+消重アルゴリズム:
 
?
1
27 > ordsets :from_list (List). [ 1 , 2 , 3 , 4 ]
4、
 
?
1
2
3
4foldl(Fun(Elem, AccIn), Acc0, List) -> Acc1  %%AccIn Acc0, Elem List , List   lists :foldl (fun(Key, Acc) ->[proplists :get_value (Key, Options) | Acc]  end ,  [], lists :reverse ([pool_id, hostname, port, username,password,database, logfun, encoding, poolsize])) : Options= "[{hostname," localhost "}, {username, " root "}, {password," sa "}, {database, " test "}]" [undefine, "localhost" , undefine, "root" , "sa" , "test" , undefine, undefine, undefine]