From ok@atlas.otago.ac.nz Tue Aug  7 02:53:00 2001
Received: from atlas.otago.ac.nz (atlas.otago.ac.nz [139.80.32.250])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f770qwb08535
	for <prolog@swi.psy.uva.nl>; Tue, 7 Aug 2001 02:52:59 +0200 (MET DST)
Received: (from ok@localhost)
	by atlas.otago.ac.nz (8.9.3/8.9.3) id MAA507668;
	Tue, 7 Aug 2001 12:53:02 +1200 (NZST)
Date: Tue, 7 Aug 2001 12:53:02 +1200 (NZST)
From: "Richard A. O'Keefe" <ok@atlas.otago.ac.nz>
Message-Id: <200108070053.MAA507668@atlas.otago.ac.nz>
To: prolog@swi.psy.uva.nl, starred@tiscalinet.it
Subject: Re:  [SWIPL] Problems with streams

Armando Stellato <starred@tiscalinet.it> wrote:
	open(mario2, write, A, [alias(stream_write)]).
	write(stream_write, pippo).
	open(mario2, read, A, [alias(stream_read)]).
	read(stream_read, Char).
	
	Well, it should give me: Char=pippo

No it most certainly should not.  It should give you an end of file error.

	but it gives me end of file error, why?

Because there IS an end of file error, that's why.

The `read' predicates read a TERM, and if you check the syntax for
terms, the closing full stop ('.' followed by at least one layout
character such as space, tab, or newline) is a REQUIRED part of the syntax.

Had you done

	write(stream_write, pippo),
	write(stream_write, '.\n')

then you would have got the result you expected.

This is one of the reasons why Quintus Prolog included a
portray_clause/1 predicate, which wrote a term out indented as
a clause, and included the terminating full stop.

	I've tried all the possible combinations, all kind of writes, closing
	the write_stream (so to be sure to have debuffered it) and then opening
	the read_stream and one thousand other things....
	why the hell doesn't it go in the right way????
	
Because the built in predicates are doing exactly what they are documented
as doing.
	
write/[1,2] is a *building* block that you can use for building up
a piece of output; to be useful for that, it MUST NOT write a terminating
full stop.

The basic problem is that Prolog uses operator precedence syntax for
data, so some explicit mark is required to end a term.

