6.1.2050
QUIT
 
CORE
 
( -- ) ( R: i * x -- )

Empty the return stack, store zero in SOURCE-ID if it is present, make the user input device the input source, and enter interpretation state. Do not display a message. Repeat the following:

  • Accept a line from the input source into the input buffer, set >IN to zero, and interpret.
  • Display the implementation-defined system prompt if in interpretation state, all processing has been completed, and no ambiguous condition exists.

Implementation:
: QUIT
   ( empty the return stack and set the input source to the user input device )
   POSTPONE [
     REFILL
   WHILE
     ['] INTERPRET CATCH
     CASE
     0 OF STATE @ 0= IF ." OK" THEN CR ENDOF
     -1 OF ( Aborted ) ENDOF
     -2 OF ( display message from ABORT" ) ENDOF
     ( default ) DUP ." Exception # " .
     ENDCASE
   REPEAT BYE
;

This assumes the existence of a system-implementation word INTERPRET that embodies the text interpreter semantics described in 3.4 The Forth text interpreter. Further discussion of the interpret loop can be found in A.6.2.0945 COMPILE,.