我需要删除列表中的最后一个元素。我在shell中运行此代码。
Erlang R16B03(erts-5.10.4)[source] [64-bit] [smp:4:4] [async-threads:10] [kernel-poll:false]
erl + pc unicode
ColumnListWithCommas = [<<"username">>,<<",">>,<<"password">>,<<",">>,
<<"created_at">>,<<",">>,<<"id">>,<<",">>,<<"email_hash">>,
<<",">>,<<"status">>,<<",">>,<<"mess_count">>,<<",">>].
lists:droplast(ColumnListWithCommas).
** exception error: undefined function lists:droplast/1
答案 0 :(得分:6)
在Erlang R16B03中没有列表:droplast / 1。 你需要Erlang 17.0
你可以这样做:
1> A = [1, 2, 3, 4].
2> lists:reverse(tl(lists:reverse(A))).
[1,2,3]
Or
3> {L, _} = lists:split(length(A) - 1, A).
又一个方法。您可以从Erlang来源获取realization非常简单