[plt-scheme] no #!eof

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Apr 14 21:42:29 EDT 2008

At Mon, 14 Apr 2008 16:37:24 -0700, "Joe Marshall" wrote:
> >
> > I imagine there's a good reason I haven't thought of why #!eof is a bad
> > idea, but I thought I'd ask in case it's an oversight.
> If EOF has a printed representation, what is the reader to do if
> it encounters it in a file?
> If I write the EOF object to a file, can I write anything after it?
> What if I write a list to file that has the EOF object in the middle of
> it?
> How do I put a literal EOF object in a file so I can write
> (define eof-object? (lambda (x) (eq? x '<what goes here?>)))

I'm not a fan of `#!eof', but I have to admit that a reader can treat
an eof in the character stream as different from a representation of a
literal eof.

In fact, if you install

  #lang scheme/base
  (provide read read-syntax)
  (define (read in) eof)
  (define (read-syntax in src) eof)

as "eof/lang/reader.ss" in your "collects" directory, then `#!eof' will
work mostly as Dave suggests --- when reader extensions are enabled,
because `#!' is equivalent to `#lang ' when followed by an ASCII
alphabetic character.[*]  A whitespace character has to follow `#!eof',

If you put up with the whitespace, there's no confusion in contexts
where `read-syntax' is used. For example, MzScheme's REPL keeps going:

 > #!eof

This works because `read-syntax' wraps the eof of `#!eof' as a syntax
object, while a character-stream eof produces a plain eof.

All that said, the result of `read' doesn't distinguish an immediate
`#!eof' from a character-stream eof, so building in `#!eof' seems
likely to create trouble.

[*] Mainly for `#!r6rs'. Bug: `#!' wasn't disabled by
    `(read-accept-reader #f)', and that's now fixed in SVN.


Posted on the users mailing list.