`

快乐的倒腾之lists学习

阅读更多

erlang包里有个lib文件。

stdlib学习

%append 
-module(lists_1).
-export([start/0, start/1]).

start()->lists:sum([1,2,3,4]).
%result 10
start(1)->
    lists:append([1,2],[3,4]);%no' . 'cast error
%result [1,2,3,4]
start(2)->
    lists:concat(["abc", 'def', 23]);
%result "abcdef23"
start(3)->
    lists:concat([23,'efd','%']);
%result "23efd%"
start(4)->
    lists:delete("lylian", ["lylian", "love", "somebody", 23]);
%result ["love", "somebody", 23]
start(5)->
    lists:duplicate(3, "lylian").
%result ["lylian", "lylian", "lylian"] 

start(6)->
    lists:flatlength([1,2,3,4,5,6,7,8,9]);
%result 9

start(7)->
   lists:flatten([1,2,3,4,5,6,7,8,9],[11,12,13]);
%result  [1,2,3,4,5,6,7,8,9,11,12,13]

start(8)->
    lists:keydelete("K", 1,[{"A"},{"K"},{"K"},{"K"},{"B"},{"c"}]);
%result [{"A"},{"K"},{"K"},{"B"},{"c"}]

start(9)->
    lists:keydelete("K", 1, ["A", "k", "K", "K"]);
%result ["A","k","K","K"](this is not good for using the function.)

start(10)->
    lists:keymember("k" , 1, [{"k"}, {"K"}]);
%result true

start(11)->
    lists:keymerge(1, [{"k"}, {"K"}],[{"k1"}, {"K2"}]).
%result [{"k"},{"K"},{"k1"},{"K2"}]

start(12)->
    lists:keyreplace("k", 1, [{"k"}, {"k"}, {"A"}], {"a"}). 
%result [{"a"},{"k"},{"A"}]
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics