«« «» »» |
Forth programmer at work: MANY ( -- ) >IN @ STOP? AND >IN ! ;Wait a minute, STOP? is not a standard Forth word. Let's focus on that first. Forth file: ec210.frt \ MANY TIMES (Albert Nijhof) FORTH DEFINITIONS DECIMAL : STOP? ( -- true/false ) KEY? DUP IF DROP KEY BL OVER = IF DROP KEY THEN 27 OVER = IF -28 THROW THEN BL <> THEN ; ) 1000 MS STOP? . [rtn] ?Gives zero. But enter the same again, and press another key immediately after the [rtn]. Three possibilities.
This seems terribly complicated, but it's quite natural when you get the hang of it. STOP? (as mentioned, not a standard Forth word) is used a lot in words like WORDS, SEE, DUMP, etc., words that produce text that can run off the screen. With STOP? it is possible to toggle output (temporarily) on and off, or to abort output completely. : MANY ( -- ) >IN @ STOP? AND >IN ! ;As long as STOP? produces zero, >IN is made zero: Forth is fooled, and 'thinks' it hasn't yet read the line, starting at the very first character again. With MANY, interactive loops are possible: ) 888 . MANY DROP [rtn] ?Utterly useless, but: ) BL [rtn] ) DUP EMIT 1+ MANY DROP [rtn] ? |