Friday, 15 February 2019

Prolog: Check whether given element is list or not


Below snippet checks whether given element is list or not.

listDemo.pl
isList([]).
isList([_|Tail]) :- isList(Tail).

1 ?- consult(listDemo).
true.

2 ?- isList([]).
true.

3 ?- isList([2]).
true.

4 ?- isList([2, 3, 5]).
true.



Previous                                                 Next                                                 Home

No comments:

Post a Comment