[ Type Testing | Reference Manual | Alphabetic Index ]


Succeeds if Term is a proper list.
Prolog term.


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).
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


    ?- 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