[clean-list] newbie: simple console IO and 65536

fzuurbie@inter.nl.net fzuurbie@inter.nl.net
Tue, 11 Mar 2003 08:04:31 UT


This is a multi-part message in MIME format.

--_----------=_1047369871258374
Content-Disposition: inline
Content-Length: 1655
Content-Transfer-Encoding: binary
Content-Type: text/plain

Isaac wrote:

> Puzzled by the behaviour of this simple console IO
> program (on Windows XP). After echoing back an
> inputline, 65536 appears on the console? How do I
> avoid this behaviour?
> 
> ---------------
> module echoline
> import StdEnv
> 
> Start:: *World -> *World
> Start world
> 	# (console, world) = stdio world
> 	  (ln, console) = freadline console
> 	  console = fwrites ln console
> 	  (ok, world) = fclose console world
> 	|  not ok = abort "problem!"
> 	= world
> ---------------
> I:\Clean>echoline -con
> input line
> input line
> 65536

Usually it is enough to set one of the Application options to 'no console'. Even in your case, where you use the console, this is the first step. A minor problem is then that you won't even have the time to watch what the program echos: the program will exit immediately after it has displayed the echoed line and remove the console window.

To remedy this, you can add an extra line of code as follows, which lets the program wait for another CRLF before exiting.

Okay, this is a remedy. I am as puzzled as you are why the strange number is displayed in the first place. It is the standard way a program exits though. It certainly isn't a programming error on your part.

Regards Erik Zuurbier


module echoline
import StdEnv

Start:: *World -> *World
Start world
        # (console, world) = stdio world
          (ln, console) = freadline console
          console = fwrites ln console
          (ln, console) = freadline console	// added line
          (ok, world) = fclose console world
        |  not ok = abort "problem!"
        = world



--_----------=_1047369871258374--