Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between :- and ?- in Prolog?

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?

like image 998
Flux Avatar asked Oct 24 '18 09:10

Flux


People also ask

What is the difference between \= and \== in Prolog?

\= 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.

What does \+ mean in Prolog?

\+ = 'if unsure or false , assume false '

How do you compare strings in Prolog?

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").


2 Answers

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.

like image 168
mat Avatar answered Sep 19 '22 23:09

mat


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.

like image 21
false Avatar answered Sep 18 '22 23:09

false