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

Re: peek/close



 > Suppose after a character is poken from an input-port, that this port
 > is closed. Is it possible, erroneous or should it signal an error: to
 > peek that input stream and still get the same character? More precisely:

I would say it is erroneous.

R4RS says two things about reading from ports:

 -- essential procedure: close-input-port PORT
 -- essential procedure: close-output-port PORT
     Closes the file associated with PORT, rendering the PORT incapable
     of delivering or accepting characters.

and

 -- essential procedure: read
 -- essential procedure: read PORT
     ... It is an error to read from a closed port.

Is it reasonable to assume that the error mentioned in READ
this was meant to apply to the other input procedures?  If
so, it is an error.


After the port is closed it is incapable of delivering
characters, so if no error is signalled, then it might be
reasonable to expect:

	(char? (peek-char <closed-input-port>)) --> #F


There is no such language under the `Output' subsection, so
should an implementation should allow

	(display "" <a-closed-output-port>)

because no characters are output?

 > (let ((char  #f)
 >       (input #f) )
 >   (call-with-input-file "foo.scm"
 >     (lambda (in)
 >      (set! input in)
 >      (set! char (peek-char in)) ) )
 >   (equal? (peek-char input) char) )      
 > ;;; --> #t  (sci, oscheme, bigloo )
 > ;;; --> error (elk, scm, scheme48 )

Another small point:

	(equal? (peek-char in) (peek-char in))

could yield #F: PEEK-CHAR may return a different object
satisfying EOF-OBJECT? on every call if there are no more
characters available in an open input port.  The report does
not say that eof-objects would normally be regarded as the
same object in the sense of EQV?