I need to delete last element in list. I run this code in shell.
erl +pc unicode
Erlang R16B03 (erts-5.10.4) [source] [64-bit] [smp:4:4] [async-threads:10] [kernel-poll:false]
ColumnListWithCommas = [<<"username">>,<<",">>,<<"password">>,<<",">>,
<<"created_at">>,<<",">>,<<"id">>,<<",">>,<<"email_hash">>,
<<",">>,<<"status">>,<<",">>,<<"mess_count">>,<<",">>].
lists:droplast(ColumnListWithCommas).
** exception error: undefined function lists:droplast/1
The easiest way to write it is actually Enum. drop(list, -1) .
This is the function that is called: set_viewer_values(Value, ViewerSet) -> if ViewerSet /= empty_set -> lists:map(fun(ViewerPid) -> ViewerPid ! {self(), set_value, Value} end, ViewerSet) end.
The List is a structure used to store a collection of data items. In Erlang, Lists are created by enclosing the values in square brackets. Following is a simple example of creating a list of numbers in Erlang.
In Elixir and Erlang we use `list ++ [elem]` to append elements.
There is no lists:droplast/1 in Erlang R16B03. you need Erlang 17.0
You can do:
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).
And one more way. You can take realization from Erlang sources it is pretty simple
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With