live/repl.ss
#lang scheme/base

;; Minimalistic REPL for a string evaluator like 'forth-command.

(require
 scheme/control  ;; for 'prompt so errors don't kill the REPL
 ;; readline/rep ;; readline command line editing (not standard on XP, so commented out)
)
(provide repl)

(define (repl command [OK "OK"])
  (printf "Press ctrl-D to quit.\n")
  (with-handlers ((void void))
    (file-stream-buffer-mode (current-output-port) 'none))
  (let loop ()
    (when OK (command OK)) ;; prints OK if there's a connection
    (let ((cmd (read-line)))
      (unless (eof-object? cmd)
        (prompt (command cmd))
        (loop))))
  (printf "Dada.\n"))