Omar Sherif
Omar Sherif

Reputation: 55

swi-prolog won't answer query

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

Answers (1)

Will Ness
Will Ness

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

Related Questions