I have a problem shown below.
Define integer list as follows:
- the empty list is an integer list
- if L is an integer list and N is an integer then [N | L] is an integer list
- if L1 and L2 are integer lists, so is [L1 | L2].
Write a prolog program integer_list(L)
that is satisfied if only if L
is an integer list.
My program cannot implement the 3rd requirement. Can someone point out to me the mistake?
int_list([]):-!.
int_list(L):-
is_list(L),
L=[X|Y],
check(L).
int_list(L):-
L=[L1|L2],
is_list(L1),
is_list(L2),
check(L1),
check(L2).
check([]):-!.
check([X|Y]):-
integer(X),
check(Y).