📜  Erlang-列表

📅  最后修改于: 2020-11-04 05:53:10             🧑  作者: Mango


列表是用于存储数据项集合的结构。在Erlang中,列表是通过将值括在方括号中来创建的。

以下是在Erlang中创建数字列表的简单示例。

-module(helloworld). 
-export([start/0]). 

start() -> 
   Lst1 = [1,2,3], 
   io:fwrite("~w~n",[Lst1]).

上面示例的输出将是-

输出

[1 2 3]

现在让我们讨论List可用各种方法。请注意,列表库需要导入才能使这些方法起作用。

Sr.No Method and Description
1

all

Returns true if Pred(Elem) returns true for all elements Elem in List, otherwise false.

2

any

Returns true if Pred(Elem) returns true for at least one element Elem in List.

3

append

Returns a new list List3 which is made from the elements of List1 followed by the elements of List2.

4

delete

Deletes an element from the list and returns a new list.

5

droplast

Drops the last element of a List.

6

duplicate

Returns a list which contains N copies of the term Elem

7

last

Returns the last element of the list

8

max

Returns the element of the list which has the maximum value.

9

member

Checks if an element is present in the list or not.

10

min

Returns the element of the list which has the minimum value.

11

merge

Returns the sorted list formed by merging all the sub-lists of ListOfLists.

12

nth

Returns the Nth element of List.

13

nthtail

Returns the Nth tail of the List.

14

reverse

Reverses a list of elements.

15

sort

Sorts a list of elements.

16

sublist

Returns a sublist of elements.

17

sum

Returns the sum of elements in the list.