[ Type Testing | Reference Manual | Alphabetic Index ]
is_list(?Term)
Succeeds if Term is a proper list.
- Term
- Prolog term.
Description
Used to test whether Term is a proper list, i.e. either the empty list,
of a list element whose tail is itself a proper list. The predicate
could be recursively defined as:
is_list(X) :- var(X), !, fail.
is_list([_|Xs]) :- is_list(Xs).
is_list([]).
The complexity of this operation is linear in the length of the list.
Modes and Determinism
Fail Conditions
Fails if Term is not a proper list
Examples
?- is_list([]).
Yes (0.00s cpu)
?- is_list([1,2,3]).
Yes (0.00s cpu)
?- is_list([1,2|3]). % illegal tail
No (0.00s cpu)
?- is_list([1,2|_]). % open-ended list
No (0.00s cpu)
?- is_list(list).
No (0.00s cpu)
?- is_list(42).
No (0.00s cpu)
?- is_list(X).
No (0.00s cpu)
See Also
atom / 1, callable / 1, compound / 1, is_array / 1, ground / 1