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

Re: #\EOF



    Date: 19 September 1980 21:32-EDT
    From: David A. Moon <MOON at MIT-MC>

    ... TYI is defined to return -1 at EOF.  This is part of the language,
    it is not an operating system dependency and should not be expected to vary
    across systems. (In fact, ITS returns 777777000003 at EOF, not -1).

That's not true. The Maclisp TYI function runs the EOFFN if it exists, but if
no EOFFN exists, it returns its second arg (if no 2nd arg and no eoffn, then
an error). Eg, (TYO stream 3) is going to return 3 on end of file. Since -1
is a good end of file value, #\EOF would be a good equivalent. 
(TYIPEEK () stream n) should also return n on EOF but fails to due to a Maclisp
bug which leaves it returning -1 always. In any case, the -1 makes very little
sense conceptually while the #\EOF reminds the reader of its intent.

    Furthermore, TYI is the only function that returns -1 at EOF.  READ and
    READLINE take an argument which is what to return (and it doesn't default
    to -1!) and IN doesn't return anything, but gives an error.

I am not swayed by this argument any more than I would be swayed by an argument
that #\TAB is a meaningless thing to have around because READLINE could never
return it. In fact, (READLINE stream #\EOF) would be perfectly well-defined.
So would (READ stream #\EOF) although the result of such a read would be a
bit ambiguous.

The fact that IN cannot take such an arg is sad, but I don't know what to say.
Perhaps IN should take an optional second arg in case the stuff being IN'd is
sufficiently constrained to make it useful to say (IN stream n).

The particular semantics of IN/OUT, READ, TYI, etc are not really in question,
however. The point is that I have to specify a number. In some system where
negative numbers meant something to TYI, my code would break. I admit that's
a case *not* worth worrying about, but it still happens that I would like
symbolic type-in modes (ie #\ or #/ things) for all character primitives and
-1 is something TYI could return.

-kmp