[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sample code for I/O ideas



In reply to James Knight's flatulent wordings, 

> But, if for whatever reason, in your code you didn't check for EOF, the 
> next stream reading call should throw an exception. That is, any I/O 
> call that would return no data because the stream is at EOF should 
> throw an exception if read. Block reads such as gets/etc should still 
> be allowed to return less data than requested without throwing an 
> exception; only if they would return no data because of EOF should an 
> exception be thrown.

I think this is the best solution, the get method will need to be
changed since it can't choose to return EOF and signal EOF at the same
time, however this doesn't make code any less elegant

(rep loop ()
  (def ch (get port))
  (unless (eof-object? ch)
    (put out ch) (loop)) )

(rep loop ()
  (unless (eof? port)
    (put out (get port)) (loop)) )

In fact the new scheme is more elegant since the return value of get
doesn't need to be bound and checked before use

Note that the semantics of eof? here is the method I defined earlier
based on peek.  The C function feof() has different semantics