English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
A list is a structure used to store a collection of data items. In Erlang, lists are created by enclosing values in square brackets.
The following is a simple example of creating a number list in Erlang.
-module(helloworld). -export([start/0]). start() -> Lst1 = [1,2,3], io:fwrite("~w~n",[Lst1]).
The output of the above example will be-
Output results
[1 2 3]
Now let's discuss the various methods available for lists. Please note that the list library needs to be imported for these methods to take effect.
Serial number | Methods and descriptions |
---|---|
1 | If Pred (Elem) returns true for all elements Elem in the List, then return true; otherwise, return false. |
2 | Returns true if Pred (Elem) returns true for at least one element Elem in the List. |
3 | Return a new list List3The list is made up of List1of the elements and List2consists of the elements. |
4 | Delete an element from the list and return a new list. |
5 | Delete the last element of the list. |
6 | Return a list containing N copies of the term Elem |
7 | Return the last element of the list |
8 | Return the element with the maximum value in the list. |
9 | Check if an element exists in the list. |
10 | Return the element with the minimum value in the list. |
11 | Return a sorted list formed by merging all sublists of ListOfLists. |
12 | Return the Nth element of the List. |
13 | Return the Nth tail of the list. |
14 | Reverse the element list. |
15 | Sort the element list. |
16 | Return the sublist of elements. |
17 | Return the sum of the elements in the list. |