[R6RS] End of file object
William D Clinger
will at ccs.neu.edu
Wed Mar 29 16:46:36 EST 2006
>From SRFI 81, as quoted by Mike:
> In R5RS, the distinct type of end of file objects is primarily
> for the benefit of read, where end of file must be denoted by an
> object that read cannot normally return as a result of parsing
> the input. However, it does not seem necessary to drag in the
> complications of this separate object into the other I/O
> operations, where #f is perfectly adequate to represent end of
> file.
In other words, #f can be used to indicate end of file
for some but not all input operations, whereas an end
of file object could be used for all input operations.
I prefer the uniformity of using the same mechanism to
indicate end of file for all input operations.
Mike wrote:
> Alternatively, I cringe every time I type:
>
> (let ((thing (read-char p)))
> (if (eof-object? thing)
> ...
> ...))
>
> and would rather type:
>
> (cond
> ((read-char p)
> => (lambda (ch)
> ...))
> (else ...))
Mike's cringing could be ameliorated by a slight extension
to cond (untested but trivial):
(define-syntax cond
(syntax-rules (else => eof=>) ; extension
((cond (else result1 result2 ...))
(begin result1 result2 ...))
((cond (test => result))
(let ((temp test))
(if temp (result temp))))
((cond (test => result) clause1 clause2 ...)
(let ((temp test))
(if temp
(result temp)
(cond clause1 clause2 ...))))
; begin extension
((cond (test eof=> result))
(let ((temp test))
(if (not (eof-object? temp)) (result temp))))
((cond (test eof=> result) clause1 clause2 ...)
(let ((temp test))
(if (not (eof-object? temp))
(result temp)
(cond clause1 clause2 ...))))
; end extension
((cond (test)) test)
((cond (test) clause1 clause2 ...)
(let ((temp test))
(if temp
temp
(cond clause1 clause2 ...))))
((cond (test result1 result2 ...))
(if test (begin result1 result2 ...)))
((cond (test result1 result2 ...)
clause1 clause2 ...)
(if test
(begin result1 result2 ...)
(cond clause1 clause2 ...)))))
Will
More information about the R6RS
mailing list