Reputation: 55
I'm trying to write a query that will make sure an element is present in a list of lists, I tried this implementation:
membernested(E,[H|T]):-member(E,H).
membernested(E,[H|T]):-membernested(E,[T]).
but Prolog won't answer the query, any thoughts?
Upvotes: 2
Views: 76
Reputation: 71119
Change you second clause to:
membernested(E,[H|T]) :- membernested(E,T).
The tail of the list [H|T]
is T
, not [T]
. There's no need to enclose it in another list.
Upvotes: 1