无涯教程-Erlang - droplast函数

201 阅读1分钟

删除列表的最后一个元素。该列表应为非空,否则该函数将因function_clause而出错。

droplast - 语法

droplast(List1)
  • List1 - 值列表。

droplast - 返回值

返回删除了最后一个元素的新列表。

-module(helloLearnfk). 
-import(lists,[droplast/1]). 
-export([start/0]). 

start() -> Lst1=[1,2,3], Lst2=droplast(Lst1), io:fwrite("wn",[Lst2]).

当我们运行上面的程序时,我们将得到以下输出。

[1,2]

参考链接

www.learnfk.com/erlang/erla…