There are two `worlds'. If you use Prolog interactively you typically
do not use read/write, but just pose queries and get answers from the
toplevel loop. Thatway you can easily combine queries, use their output
for other tasks in Prolog, etc.
If you use it as an application, you typically either provide the query
on the commandline or add it to the application using
initialization/1,2. E.g., you can do (note that format/2,3 is a much
nicer way to write output for users than lots of write calls).
% swipl -g "a(W,1),format('My number is ~w~n',[W])" -t halt
myprog.pl
Or you can add this to your file:
:- initialization(go, main).
go :-
a(_W,1),
format('My number is ~w~n',[W]).
and run
% swipl
myprog.pl
or add a first line as below, make the file executable (chmod +x
myprog.pl)
and simply run as ./
myprog.pl
#!/usr/bin/env swipl
or, finally
% swipl -o myprog -c
myprog.pl
% ./myprog
This all assumes a fairly recent version of SWI-Prolog and a non-windows
system. On Windows you can do similar things, but it is all a bit
different.
Cheers --- Jan
> --
> You received this message because you are subscribed to the Google
> Groups "SWI-Prolog" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
swi-prolog+...@googlegroups.com
> <mailto:
swi-prolog+...@googlegroups.com>.
> Visit this group at
https://groups.google.com/group/swi-prolog.
> For more options, visit
https://groups.google.com/d/optout.