Re: Reading from a File



You should read an user manual. However, if you have space in a filename you
have to use single quotes.
(Exempli Gratia: Filename = 'my file name.ext'). You have to pass a Stream
to read/2 (read/1 is used for standard input), not a filename.
Id est:
| ?- open(Filename, read, Stream), read(Stream, Term), ... , close(Stream).
Please note that read/2 attempts to read a Prolog term. If what you read is
not a valid term, an error is raised.
Try to take a look, at least, to an user manual.
I suggest SWI Prolog one, freely downloadable from
http://www.swi-prolog.org/.
Regards,
M






"imaguest" <williamglennrocks@xxxxxxxxxxx> ha scritto nel messaggio
news:1128726904.027459.118420@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Hi,
>
> I am learning prolog and although It seems like I understand how to
> read from a file, when I actually try, I have a number of problems.
>
> I am trying to read(F) where F is a file, but if I have any spaces in
> the File F or the text doesn't end in a period, I have problems, and
> nothing is read.
>
> i.e. a b will give me two problems, one, there is a space, and it says:
> Operator Expected, also, even before I get that error, I get an error
> saying: Unexpected end of file.
>
> It seems to me that the read(F) is treating F like a prolog file, and
> applying the rules to F that you would to F.pl, is that the case?
>
> I have looked around quite a bit looking for a solution but I haven't
> found anything, so any help, would be, well helpful.
>
> Thanks
>


.