On Tuesday, May 5th, 2026 at 3:54 PM, Bernd Paysan <[email protected]> wrote:
> Am Dienstag, 5. Mai 2026, 17:31:53 Mitteleuropäische Sommerzeit schrieb > jlyonm > via Gforth discussion and announcements: > > On Tuesday, May 5th, 2026 at 1:55 AM, Mark J. Reed <[email protected]> > wrote: > > > 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? > > I'm reading one character at a time. > > > > > > 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? > > > > In the Gforth info document, section 2.6 it says, "If you pipe into Gforth, > > your program should read with `read-file' or `read-line' from `stdin'. > > `Key' does not recognize the end of input." This is exactly what I am > > seeing with my little program. It never exits. > > KEY does recognize end of file, but it throws an exception instead of passing > a > flag. > > For that purpose, there is now (in the development snapshot) KEY-IOR, which > returns a negative value for end of file or other exceptions. > > $ echo "check this" | gforth -e ": test begin key-ior dup 0>= while h. repeat > drop ; test cr bye" > $63 $68 $65 $63 $6B $20 $74 $68 $69 $73 $A > > End of file is error code -512 (which translates into “success” if thrown, as > there is no errno assigned to EOF). > Thanks for the extra details. I did not know about any of this. > > > Just use stdin file-eof? ? > > > > Thanks a lot, this is exactly what I needed, and makes it work. How does one > > find that word? It is not in the info docs, nor can I find it online. I > > wonder what else I am unaware of. > > FILE-EOF? is documented in the current development manual. > > https://net2o.de/gforth/ > > Go to the index, search for EOF, and second hit is it. > I am definitely bookmarking this page. I only knew about these pages on Gforth: https://www.gnu.org/software/gforth/ https://www.complang.tuwien.ac.at/forth/gforth/Docs-html/ > > > > 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. > > The termux version is likely 0.7.3, and the development documentation can be > significantly ahead of the functions available there. > You are correct, termux has Gforth 0.7.3. I should have checked and provided the version. > -- > Bernd Paysan > "If you want it done right, you have to do it yourself" > net2o id: kQusJzA;7*?t=uy@X}1GWr!+0qqp_Cn176t4(dQ* > https://net2o.de/ >
publickey - [email protected] - 0x2EE30A91.asc
Description: application/pgp-keys
signature.asc
Description: OpenPGP digital signature
