Erlang - droplast 函数
删除列表的最后一个元素。 该列表应该非空,否则函数将因 function_clause 崩溃。
语法
droplast(List1)
参数
List1 − 值列表。
返回值
返回删除最后一个元素的新列表。
例如
-module(helloworld). -import(lists,[droplast/1]). -export([start/0]). start() -> Lst1 = [1,2,3], Lst2 = droplast(Lst1), io:fwrite("~w~n",[Lst2]).
输出
当我们运行上面的程序时,将得到以下结果。
[1,2]