[R6RS] End of file object

Anton van Straaten anton at appsolutions.com
Wed Mar 29 21:25:59 EST 2006

Will wrote:
> Mike's cringing could be ameliorated by a slight extension
> to cond

I'm not sure that extending COND is the right solution, for two reasons:

1. The extension would have to come with a warning that it isn't safe 
for use with READ.

2. The extension can't be used in contexts other than COND.

A similar effect could be achieved with a procedure, which has the 
benefit of being composable and usable in other contexts, e.g.:

(define test-eof
   (lambda (x)
     (if (eof-object? x) #f x)))

While this is still not safe for use with READ, I find it more 
acceptable to document that restriction on a standalone procedure, than 
on a piece of syntax that's part of COND.

This would allow Mike to write the following:

   ((test-eof (read-char p))
    => (lambda (ch) ...)) ...)

...which is only a procedure call away from his preferred version:

   ((read-char p)
     => (lambda (ch) ...)) ...)

It also allows variations like this:

(case (test-eof (read-char p))
   ((#f) (raise "The End."))

...and it works with anaphoric macros, too.

BTW, is there not an efficiency issue here, i.e. might it be easier for 
a compiler to optimize the case where read-char returns #f directly?


More information about the R6RS mailing list