lists:nth/2
获取列表里的第 N 个元素
用法:
nth(N, List) -> Elem
内部实现:
%% nth(N, L) returns the N'th element of the list L
-spec nth(N, List) -> Elem when
N :: pos_integer(),
List :: [T,...],
Elem :: T,
T :: term().
nth(1, [H|_]) -> H;
nth(N, [_|T]) when N > 1 ->
nth(N - 1, T).
获取列表里的第 N 个元素
lists:nth(3, [1, 2, 3, 4, 5]).