title: SWI Prolog - conditional NOT?
body: <p>I'm trying to make a prolog function. The function reads in a sentence, and then tries to extract a key word. If a key word is found, it prints a message. I want it to also print a message if no keywords are found. Here is my example : </p>
  
  <pre><code>contains([word1|_]) :- write('word1 contained').
  contains([Head|Tail]) :- Head \= word1, contains(Tail).
  contains([word2|_]) :- write('word2 contained').
  contains([Head|Tail]) :- Head \= word2, contains(Tail).
  contains([word3|_]) :- write('word3 contained').
  contains([Head|Tail]) :- Head \= word3, contains(Tail).
  </code></pre>
  
  <p>The above code will check and see if the extracted word is present. But it does not give an answer if the words 'word1,word2 or word3' are not contained. Does anybody know how I should go about implementing this?</p>
  
  <p>I tried adding : </p>
  
  <pre><code>contains([_|_]) :- write('nothing contained'),nl.
  contains([Head|Tail]) :- Head \= _, contains(Tail).
  </code></pre>
  
  <p>But clearly this is the wrong thing to do.</p>