title: Creating a Knowledge Base and Querying in Prolog
body: <p>I want to create the Knowledge base equivalent to the statements as below in Prolog.</p>
  <ol>
  <li><p>John likes all kind of food.</p>
  </li>
  <li><p>Apple and vegetable are food</p>
  </li>
  <li><p>Anything anyone eats and not killed is food.</p>
  </li>
  <li><p>Anil eats peanuts and still alive</p>
  </li>
  <li><p>Harry eats everything that Anil eats.</p>
  </li>
  </ol>
  <p>So this one of the version borrowed from <a href="https://www.javatpoint.com/ai-resolution-in-first-order-logic" rel="nofollow noreferrer">here</a></p>
  <p><img src="https://i.stack.imgur.com/Tb3g9.png" alt="enter image description here" /></p>
  <p>Once this file is created I want to find the answer for the query &quot;John likes peanuts.&quot; saying <strong><code>likes(john, peanut).</code></strong></p>
  <p>Attempt to write rules in Prolog from my side is as below</p>
  <pre><code>alive(anil).
  eats(anil,peanut).
  food(apple).
  food(vegitables).
  
  food(X):-likes(john,X).
  
  eats(X,Y),not(killed(X)):-food(Y).
  
  eats(anil,X):-eats(harry,X).
  
  killed(X):-not(alive(X)).
  
  alive(X):-not(killed(X)).
  </code></pre>
  <p>But I am getting the errors and warnings as below;</p>
  <pre><code>ERROR:    No permission to modify static procedure `(',')/2'
  
  Warning:    Clauses of eats/2 are not together in the source-file
  
  Warning:    Current predicate: food/1
  
  Warning:    Use ':- discontiguous eats/2.' to suppress this message
  
  Warning:    Clauses of alive/1 are not together in the source-file
  
  Warning:    Current predicate: killed/1
  
  Warning:    Use ':- discontiguous alive/1.' to suppress this message
  </code></pre>