Re: Loading code from standard input Lassi Kortela 26 May 2020 12:38 UTC

>      > It is brittle in any case because the "script" being loaded may call
>      > `read' in between.
>
>     True. Perhaps implementations should be required to buffer the whole
>     source code from stdin before reading any of it. Otherwise the results
>     may be "artistic" :)
>
> If everything were buffered when reading from stdin, the REPL would be
> unusable: it would buffer everything you type and when you ^D (or ^Z in
> Windows) only then would you get any output.
>
> Here is a file "dog.scm"
>
> (import (scheme write))
> (import (scheme read))
> (display "Woof woof!\n")
> (display (read))
> "Arf arf!\n"
>
> When I run this with "chibi <foo.scm" it outputs both "Woof woof!" and
> "Arf arf!", along with some Chibi prompts.  When I run it with "chibi
> foo.scm", it outputs "Woof woof!" and waits for me to enter an
> S-expression from the terminal, which is then displayed; the "Arf
> arf!\n" string is read but ignored.

A Scheme implementation should check isatty(STDIN_FILENO) to figure out
whether stdin is a terminal, only running the REPL if it is. If it's not
a terminal, buffer the whole contents and then read from the buffer.
Would there be problems with this arrangement?

The Windows API ought to have an API equivalent to isatty().