2011年3月21日月曜日

Erlang データタイプ リスト

2.10  List
(リスト)

Compound data type with a variable number of terms.
(termsの数が可変であるデータ型)

[Term1,...,TermN]
Each term Term in the list is called an element.
(リスト内の各Termはエレメントと呼ばれる。)

The number of elements is said to be the length of the list.
(エレメントの数はリストの長さと同値)

Formally,
(形式として)

a list is either the empty list [] or consists of a head (first element) and a tail (remainder of the list) which is also a list.
(リストが空である もしくは 先頭とそれ以外の部分で構成されている)

The latter can be expressed as [H|T].
(後者は[H|T]のように表現することができる。)

The notation [Term1,...,TermN] above is actually shorthand for the list [Term1|[...|[TermN|[]]]].
([Term1,...,TermN]のような表記は実際には[Term1|[...|[TermN|[]]]]の簡潔な表現である。)

Example:
[] is a list, thus
[c|[]] is a list, thus
[b|[c|[]]] is a list, thus
[a|[b|[c|[]]]] is a list, or in short [a,b,c].


A list where the tail is a list is sometimes called a proper list.
(tailがあるリストは適切なリストと呼ばれる。)

It is allowed to have a list where the tail is not a list, for example [a|b].
(tailがリストでないリストもあることが許されている。[a|b]のように)

However, this type of list is of little practical use.
(しかしながら、そのようなリストはあまり実用的でない)

Examples:

1> L1 = [a,2,{c,4}].
[a,2,{c,4}]
2> [H|T] = L1.
[a,2,{c,4}]
3> H.
a
4> T.
[2,{c,4}]
5> L2 = [d|T].
[d,2,{c,4}]
6> length(L1).
3
7> length([]).
0

A collection of list processing functions can be found in the STDLIB module lists.
(リストを処理する関数系はSTDLIBモジュールで見ることができる。)

0 件のコメント:

コメントを投稿