[clean-list] Re: eof for console input

Erik Zuurbier EZuurbier@Abz.nl
Wed, 19 Mar 2003 15:00:08 +0100


This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C2EE1F.D9D0ECA0
Content-Type: text/plain

Isaac wrote:
>Start:: *World -> String
>Start world
>	# (console, world) = stdio world 
>	# (line, console) = freadline console 
>	# (ok, world) = fclose console world
>	= line
First note that the penultimate line is dead code.
>So 2 questions:
>- what's happening to use up heap space?
>- as sfend and fend cannot be used with the console,
>how can I check for eof?

I can only answer the second question: there is never ever an end-of-file on
the console.
The program can always read more from the console as long as it is open.
If you don't type in anything when the program is waiting for it, that does
not mean
that an end-of-file is reached. If you really really want to do an eof-check
on the console,
use the following code:

fendConsole :: *File -> (Bool,*File)
fendConsole console = (False,console;-)

If you think redirecting a file to play the role of the console DOES create
a need for
an eof-check in a console, well too bad: Clean's designers probably had not
foreseen
redirections. Use fopen instead of stdio. If you want to be able to abstract
out the file type
(physical file or console) apply for a redesign of the StdFile module. I can
imagine that
a redesign may bring more benefits. For instance if type classes were used,
I can imagine
that the typechecker could discriminate read-files from write-files,
data-files from text-files
etc. moving various run time errors (e.g. writing to a read-file) to the
realm of compile time
checks.

Regards Erik Zuurbier 


 best wishes, Isaac 


------_=_NextPart_001_01C2EE1F.D9D0ECA0
Content-Type: text/html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">



Re: eof for console input



Isaac wrote:
>Start:: *World -> String
>Start world
>       # (console, world) = stdio world
>       # (line, console) = freadline console
>       # (ok, world) = fclose console world
>       = line
First note that the penultimate line is dead code.
>So 2 questions:
>- what's happening to use up heap space?
>- as sfend and fend cannot be used with the console,
>how can I check for eof?

I can only answer the second question: there is never ever an end-of-file on the console.
The program can always read more from the console as long as it is open.
If you don't type in anything when the program is waiting for it, that does not mean
that an end-of-file is reached. If you really really want to do an eof-check on the console,
use the following code:

fendConsole :: *File -> (Bool,*File)
fendConsole console = (False,console;-)

If you think redirecting a file to play the role of the console DOES create a need for
an eof-check in a console, well too bad: Clean's designers probably had not foreseen
redirections. Use fopen instead of stdio. If you want to be able to abstract out the file type
(physical file or console) apply for a redesign of the StdFile module. I can imagine that
a redesign may bring more benefits. For instance if type classes were used, I can imagine
that the typechecker could discriminate read-files from write-files, data-files from text-files
etc. moving various run time errors (e.g. writing to a read-file) to the realm of compile time
checks.

Regards Erik Zuurbier


 best wishes, Isaac

------_=_NextPart_001_01C2EE1F.D9D0ECA0--