Subject: Re: input/output redirect

From: Nicos Angelopoulos <[email-masked]>
Date: Thu, 24 Aug 2000 11:42:09 +0100

On Wed, 23 Aug 2000, Manny Obrey wrote:

> 
>   hello,
> 
>       i'd like to do the following
> 
>       >prolog -c database < inputfile > outputfile
> 
>       where 'database' is a file w/ clauses,
>       'inputfile' contains queries, and
>       'outputfile' contains the output from the queries.
>       All i end up w/ however is an empty 'outputfile'.
> 
>       any hlp for a newbie app.
>       - manny
> 

1. you should change -c to -f, alternatively, use -g consult(database).

eg

% pl -f database < inputfile > outputfile
 
% pl -g 'consult(database)' < inputfile > outputfile

2. an alternative way would be to change your inputfile to
something like

:- consult( database ).

main( OutFile ) :-
	tell( OutFile ),
	q1( _X ),
	q2( _Y ),
	...
	qn( _Z ),
	told.

% pl -g 'consult(inputfile),main(outputfile),halt'

in any case you need to make sure queries in 1. succeed only once

for a more declarative style you mind want to consider 
things like 

main( OutFile ) :-
	findall( X, q1(datum1,X), Xs ),
	once( q2(datum2,Y) ),
	tell( OutFile ),
	write( 'q1(datum1,X) - Xs :' ), write( Xs ), nl,
	write( 'once(q2(datum1,Y)) - Y :' ), write( Y ), nl,
	write( 'call(q3(datum3)) :' ), nl,
	q3(datum3), 
	told.

nicos.