> Hi,
>
> I have an urgent doubt. For example when I ask to prolog
>
> ?- member( 3, [1,2,3]).
> Yes
>
> Is there any system variable associated with the prolog answer "Yes"
> or "No" ???
I still STRONGLY suggest you read a tutorial. A couple of hours reading and
trying examples
will teach you a lot about what's going on, and I expect you would have been
beyond this
question by now if you had done so. But maybe not, as sometimes people can get
stuck on
false ideas about how Prolog works, and can't resolve the specific problem by
reading a
generic tutorial.
To answer this question. No, there is no system variable. There is a
choicepoint, which
prolog enables Prolog to go back to try alternative solutions.
?- member(A, [1,2,3])
A=1 ; % prolog gives 'A=1', you type ';'
A=2 ;
A=3 ;
no.
"Yes" means the query succeeded and no variables were bound.
A=1 means the query succeeded and A was bound to 1.
; means go back and try to find a different possible way to solve the query.
After 3 times trying different solutions, Prolog determined there were no more
solutions,
and answered "No".
Here is another program to try:
In a source file enter:
xxx(X) :- X = 2
xxx(X) :- X = 3
xxx(X) :- X = 4.
At the prompt enter:
?- xxx(A).
By defining 3 clauses for xxx you create choices. Calling xxx(AnyVariable)
invokes that
clause and creates a choice point.
Now another query to try:
?- member(A, [1,2,3]), xxx(A).
And anothe predicate to try, to see what cut does:
yyy(X) :- X = 1, !.
yyy(X) :- X = 2, !.
yyy(X) :- X = 4, !.
?- yyy(X).
?- member(X, [1,2,3], yyy(X).
In short, cut tells the program not to try any more solutions to the current
predicate.
This means if the first clause succeeds, the second won't even be tried because
it was cut
off.
|