[plt-scheme] no #!eof

From: Abdulaziz Ghuloum (aghuloum at cs.indiana.edu)
Date: Mon Apr 14 22:39:51 EDT 2008


Not talking about PLT Scheme, but other implementations do have  
reasonable answers for your questions on #!eof.

On Apr 14, 2008, at 7:37 PM, 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?

Producing an eof object is reasonable, like the one obtained by  
calling R6RS's (eof-object).

 > (read (open-string-input-port "#!eof"))
 > (eof-object? (read (open-string-input-port "#!eof")))

> If I write the EOF object to a file, can I write anything after it?

Why not?  The first call to read will return an eof object while a  
second call to read will read what comes after it.

 > (let ([p (open-string-input-port "12 #!eof 13")])
     (list (read p) (read p) (read p)))
(12 #!eof 13) ;;; in some unspecified order

> What if I write a list to file that has the EOF object in the  
> middle of
> it?

You can get a list containing an eof object.

 > (read (open-string-input-port "(12 #!eof 13)"))
(12 #!eof 13)

> 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?>)))

#!eof could go in there too: :-)

 > (let ([eof-object? (lambda (x) (eq? x '#!eof))])
     (eof-object? (read (open-string-input-port "#!eof"))))

All examples were tested on Ikarus (rev 1450) and Chez (7.4) using  
open-input-string for open-string-input-port.


Posted on the users mailing list.