[comp.lang.prolog] Yet another stupid question

ranson@crcge1.UUCP (D. Ranson CNET) (04/07/88)

What is the difference between the ?- and :- operators in front of a
goal? I have seen both used in several Prolog books or manuals, with
no discernable pattern, and without any explanation.

     Daniel Ranson
     ...!mcvax!inria!crcge1!ranson

ok@quintus.UUCP (Richard A. O'Keefe) (04/09/88)

In article <3379@crcge1.UUCP>, ranson@crcge1.UUCP (D. Ranson CNET) writes:
> 
> What is the difference between the ?- and :- operators in front of a
> goal? I have seen both used in several Prolog books or manuals, with
> no discernable pattern, and without any explanation.
> 
>      Daniel Ranson
>      ...!mcvax!inria!crcge1!ranson

What the difference is depends on the Prolog system.

In DEC-10 Prolog, the rule is that ":-" begins "commands" and "directives".
When one of these things is encountered in a file, it is processed and no
output is produced unless something goes wrong.  "?-" begins "queries",
and the bindings produced by such queries are printed exactly as if you
had typed the query at top level.  That's why the top level prompt
includes "?- ".  If you want to give a command at top level and not have
any bindings printed, you can use :-.  For example
	| ?-  :- source_file(p(_), File), compile(File).
	===== ------------------------------------------
	prompt           command
will not print the binding of File.

PDP-11 Prolog, in order to save space (it ran on PDP-11s without separate
I&D space, and 64kbytes is not a large address space) didn't allow an
operator to be both infix and prefix, so in PDP-11 Prolog you had to use
?- for commands and directives, and couldn't put queries in files.

Quintus Prolog doesn't distinguish between ?- and :- in files.
I'd never actually noticed this, because I've never wanted to put a query
in a file and have the bindings printed on the terminal.  However, the
trick of putting a :- in front of a top-level query to suppress the printing
of the bindings is supported.

I suggest that you forget about ?- and stick to :- .  If you come across
a Prolog system where you have to use ?- you will probably have to make a
lot of other changes as well.

Check your books again, though.  They may be writing the ?- to show you
the top-level prompt, as I did in the example above.