
删除List的最后一个元素。该列表应该是非空的,否则函数将崩溃,并产生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]