title: Prolog planning using retract and assert
body: <p>I wonder, is it possible to do planning in Prolog using the knowledge base modified by retract and assert during the runtime?</p>
  
  <p>My idea is as follows: assume that I need to replace a flat tire of a car. I can either put something on the ground or move something from the ground to some free place.</p>
  
  <p>So I came up with such a code:</p>
  
  <pre><code>at(flat, axle).
  at(spare, trunk).
  
  free(Where) :- at(_, Where), !, fail.
  remove(What) :- at(What, _), retract(at(What, _)), assert(at(What, ground)).
  put_on(What, Where) :- at(What, _), free(Where), retract(at(What, _)), assert(at(What, Where)).
  </code></pre>
  
  <p>(I am a rookie in Prolog so maybe that it is even wrong, if so, please advise me how to correct it.)</p>
  
  <p>The idea is: I have a flat tire on the axle and a spare one in the trunk. I can remove a thing X if X is somewhere and to remove it, I remove the fact specifying where it is and add a fact that it is on the ground. Similarly, I can put a thing X to location Y if X is somewhere and Y is free and to do so, I remove X from where it is and add the fact that X is at Y.</p>
  
  <p>And now I am stuck: I have no idea how to use this code now, since <code>at(spare, axle)</code> just says nope, even with tracing.</p>
  
  <p>So the question: can such an approach be used and if so, how?</p>
  
  <p>I hope it makes sense.</p>