This Prolog program prints Hello
:
main :-
write('Hello'), nl.
:- main.
I changed (:-)/1
to (?-)/1
:
main :-
write('Hello'), nl.
?- main.
This produces exactly the same result. This also prints Hello
.
So what's the difference between (:-)/1
and (?-)/1
?
\= means the two terms cannot be unified, i.e. that unification fails. As with all applications of negation as failure, "not unified" does not (and cannot) result in any unification between terms. \== means the two terms are not identical. Here also no unification takes place even if this succeeds.
\+ = 'if unsure or false , assume false '
Show activity on this post. /*SWI prolog code*/ string1(progga). string2(ikra). go:- write("Enter your name"), nl, read(X),nl, string1(Y), X=@=Y,nl, write("Matched"); write("not Matched"),go2. /*Another way to*/ go2:- string1(A), string2(B), A=@=B,nl, write("Matched"); write("not Matched").
The argument of term with principal functor (:-)/1
is called a directive. In the Prolog standard, it is defined in 7.4.2 Directives.
In addition, 5.5.5 states:
A processor may support one or more additional directive indicators (7.4.2) as an implementation specific feature.
So, in some Prolog systems, (?-)/1
is available as additional directive indicator.
In ISO Prolog, :-
is used for directives like operator declarations only. The ?-
operator is also defined but no meaning is given to it.
These operators stem from the DEC system 10 Prolog of ~1978 where they were called command and question respectively. While :- p(X).
just tested for the success of p(X)
during consulting, ?- p(X).
showed an actual answer and prompted for further answers. So you got some interaction while loading your files which was abandoned in subsequent systems making both operators behave in the same way.
Since DEC10, many systems print ?-
as a prompt for the top level loop, reminding that the next term read in will be interpreted and answered as a question. Some systems go even further and add the interpreter prompt |
in front of it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With