Dave Thomas wrote:

> A cat sits in a closed box in front of a keyboard. Next to it is a
> lump of radioactive catnip. If the catnip emits an alpha particle, the
> cat types ^D, signaling end of file. Otherwise the cat types the first
> character of War and Peace.
> 
> The Ruby interpreter sits outside the box, at the $stdin.feof line. It
> has a problem. In order to tell if the file is at eof, it has to read
> the next line (as the terminal is in cooked mode). If it doesn't read
> the next line, then it won't see the ^D. You'd then complain that eof
> returned false, but the next read failed because it was actually at
> EOF. If it _does_ read the line, then you complain that the prompt
> doesn't get written before the next line is read.
> 
> So the interpreter punts, and just calls the C library feof() routine,
> so it can blame the library for whatever behavior happens.

Thanks Dave.  That makes sense. It's just not how I remember I/O working 
with stdin in C, C++ or Java.  However, I've obviously misremembered, so 
I'll go back and play with some of those other poor substitutes for Ruby 
and remind myself :-).

> You can solve this fairly tidily using something like
> 
>   loop do
>     print "-> "
>     break unless line = gets
>     # process line
>   end

Yep. That's what I did when I worked out what was going on.  Thanks again.

> ps. My math isn't up to much, but from the cat's point of view, aren't
> we topologically inside the box? Does this strike anyone as dangerous?

Yes, from the cat's point of view, this is true.  But since the catnip is 
with the cat, outside the box, we're OK :-).

H.