Reputation: 49
How to append elements into Erlang list
data type when size of the list is unknown.
Sample elements: 1
, 2
, 3
, 4
.
The final list should be L = [1,2,3,4]
.
Upvotes: 0
Views: 114
Reputation: 2544
The list
in Erlang is dynamic-length, so you don't need to specify its final size in advance.
Also you can add new element to list
this way:
List0 = [],
List1 = [4|List0],
List2 = [3|List1],
List3 = [2|List2],
List4 = [1|List3],
%% => List4 = [1, 2, 3, 4].
Upvotes: 3