On Mon, May 4, 2026 at 11:53 AM jlyonm <[email protected]> wrote:
> I wanted to write a simple program that reads input from stdin, and writes > it out to stdout doing a little translation. > Ok, so does your program need to respond to each individual key press, or can it read a whole line and then process that all at once? > At first I thought I could make use of key and key?, but I see the > documentation indicates this can't be used on stdin. > I'm confused - don't those words work exclusively on stdin? > So, I tried read-line. This works mostly. I can read characters one at a > time, and the main program's begin ... while loop will terminate at EOF. > But, as one would expect by something called read-line, it consumes returns > on its own. I'd like to receive those. > Well, you can safely assume that there's a return at the end of the line. Can even append one to the string if you need to.. > > Then I tried a combination of read-file and read-line with: > > chr 0 stdin read-line > What's *chr*? > hoping to get the flag to know whether the end of the input has been > reached (which read-file doesn't provide), but this doesn't work either, > and the program hangs indefinitely. > Just use *stdin file-eof? *? > > In case it matters, I'm actually running this on a phone running Lineage > OS (ostensibly Android) under termux. I don't think it effects the behavior. > > I did find something on rosettacode: > > https://rosettacode.org/wiki/Copy_stdin_to_stdout#Forth > > So I am currently using slurp-fid to dump all of stdin into memory, and > then reading a character out and updating the address pointer as I go. > > But I was wondering if it is possible to do this from just reading > characters directly from the file descriptor. Is there some other check for > EOF I missed in the documentation? > > Thanks for reading. -- Mark J. Reed <[email protected]>
