.. (לתיקייה המכילה) | ||
How can we print in Prolog? | |
If you want to add prints in order to understand what's going on you can add the goal: write(...) this goal always succeeds and has the side-effect of writing text to the console. For example, given the following rule: test :- permutation([1,2,3],L), write(L), fail. When asking: test. We'll get [1, 2, 3][2, 1, 3][2, 3, 1][1, 3, 2][3, 1, 2][3, 2, 1] false |
when we "consult" our file we get: Warning: c:/.../ex5.pl:1: Singleton variables: [Y] should we be concerned about it? | |
It indicates that there is one or more variable in the clause that appears only once. This is never necessary as the first appearance of a variable always succeeds with a successful binding. Prolog has the anonymous variable named _ for this purpose. So just use _ instead of Y. |
Some times when finishing returning answers it returns immediately to the prompt and sometimes it waites to ; and only then return to the prompt. Why is that, and is that meters? | |
Prolog returns to the prompt when it finish going over all the rules. If it returns the answer and it finished going over all the rules it will finish the execution and return to the prompt. If there are rules that it didn't check he will wait for ';' or '.' ';' continues the execution and Prolog will continue to check the other rules (then returns another answer if there is one or finish the execution and return to the prompt) '.' finish the execution. It doesn't meters whether it waits or not. What meters is the sequence of answers. Make sure the sequence is correct and each answer is returned only once. |
In some of our "functions" after I get an answer it waits for ";" or ".", if I press ";" the it returns false. Is that a problem? | |
It is not a problem. It continue going over the rules he didn't go over yet and doesn't find other results. |