Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Louis, I'm not entirely clear on what you're aiming to do with this code, but a couple of comments that might hopefully help.</p> <p>Things that start with a capital letter in Prolog are variables to be matched against in rules. <code>_</code> is a special symbol that can be used in place of a variable name to indicate that any value can match.</p> <p><code>next_safe(_)</code> is therefore only capable of providing you with a true/false answer if you give it a specific value. One of the major benefits of Prolog is the ability to unify against a variable through backtracking (as ony said). This would mean that when written correctly you could just ask Prolog <code>next_safe(X).</code> and it would return all the possible values (safe moves) that unify with X.</p> <p>To go back to the first point about capital letters. This means that <code>OK</code> is actually a variable waiting to be matched. It is effectively an empty box that you are trying to match against another empty box. I think what you're intending is to use the value <code>ok</code> which is different. You do not assign to variables in the same way that you do in other programming styles. Something like the following might be closer to what you are looking for, though I'm still not sure it's right as it looks like you're trying to assign things but I'm not certain how your <code>nth1</code> works.</p> <pre><code>Cells = [ok, _, _, _, _, _] . ... next_safe(NewLoc) :- facing(CurrentDirection), delta(CurrentDirection, Delta), in_cell(OldLoc), NewLoc is OldLoc + Delta, nth1(NewLoc, Cells, ok). </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload