[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Fw: Reading from files?
From: |
carlos calderon |
Subject: |
Fw: Reading from files? |
Date: |
Fri, 15 Jun 2001 11:50:25 +0100 |
----- Original Message -----
From: "carlos calderon" <address@hidden>
To: <address@hidden>
Sent: Friday, June 15, 2001 11:26 AM
Subject: Re: Reading from files?
>
> ----- Original Message -----
> From: "Wolfgang Müller" <address@hidden>
> To: "carlos calderon" <address@hidden>
> Sent: Friday, June 15, 2001 6:59 AM
> Subject: Re: Reading from files?
>
>
>
> >
> > I am not much of a prolog programmer, but your problem is, that
> > > read_file_to_list(T)
> > will "call" again the rule read_file_to_list. So it will open the file
> > *again*. You have to make a rule which first opens the file, and then
> calls
> > (I don't know the right word) a rule that fills your list using an open
> file.
>
Cheers Wolfgang..
>
The following works:
go(X,Y) :-
solve(X,Y),
write2file(X,Y),
read.
read : -
open('/home/carlos/gnu_prolog/example/files/test.txt', read,
In,[type(text), alias(input)]),
/*the alias input acts as a "global variable"*/
set_input(input),
set_stream_buffering(input,none),
read_file_to_list(input,Results),
showlist(Results),
close(input).
read_file_to_list(input,Array) :-
get_char(In,Char),
(Char = end_of_file
-> Array=[]
;
Array = [Char | T],
read_file_to_list(input, T)
).
Now, it does what I want: solve, write, read, display -for every X and Y.
> > I am just asking myself if this is the right list. All these seem to me
to
> be
> > prolog problems, and not GNU prolog problems. Daniel, which list would
be
> the
> > appropriate mailing list for such questions? Could you add something to
> your
> > doc that points questions to the appropriate list in the case this is
not
> the
> > right list?
>
Again, apologise if this is not the right list. As I keep saying I am new
to
both Prolog and GNU-Prolog and after reviewing the archives... I realised
that there are very clever chaps here...so I hope nobody gets upset.
Thanks