4.8.3 Analyzing and Constructing Lists

To combine two lists to form a third list, use append(Head, Tail, List).

To analyze a list into its component lists in various ways, use append/3 with List instantiated to a proper list. The reference page for append/3 includes examples of its usage, including backtracking.

To check the length of a list call length(List, Length).

To produce a list of a certain length, use length/2 with Length instantiated and List uninstantiated or instantiated to a list whose tail is a variable.

To check if a term is the element of a list, use memberchk(Element, List).

To enumerate the elements of a list via backtracking, use member(Element, List).

To check that a term is NOT the element of a list, use nonmember(Element, List), which is equivalent to \+member(Element, List).

Send feedback on this subject.