anchor.diff:                (debug-log status "EVAL: ~A" form)
                 form)))
   
  -(defun logging-evaluated-result-sequence (forms)
  -  (lazy-map forms
  -            (lambda (form)
  -              (let ((values (multiple-value-list (eval form))))
  -                (debug-log status "RESULT: ~A" values)
  -                values))))
  -
  -(defun main-iterator (stream &key history)
  +(define-condition shell-eof (error)
  +  ())
  +
  +(defun shell-read (stream &key history (eof-error-p t) eof-value)
     (let* ((captured-input (when history (make-string-output-stream)))
            (wrapped-stream (if history (make-echo-stream stream captured-input) stream))
  -         results)
  -    (make-computed-iterator
  -      (let ((*fresh-prompt* t))
  -        (labels
  -            ((record-history ()
  -               (when history
  -                 (history-enter history (get-output-stream-string captured-input)))
  -               (setf *fresh-prompt* t))
  -             (initialize-sequence ()
  -               (setf results (as-> wrapped-stream x
  +         results
  +         (*fresh-prompt* t))
  +    (labels
  +        ((record-history ()
  +           (when history
  +             (history-enter history (get-output-stream-string captured-input)))
  +           (setf *fresh-prompt* t))
  +         (initialize-sequence ()
  +           (setf results (as-> wrapped-stream x
                                  (logging-token-sequence x)
                                  (logging-command-sequence x)
  -                               (logging-evaluation-form-sequence x)
  -                               (logging-evaluated-result-sequence x))))
  -             (reset-token-sequence ()
  -               (loop :while (read-char-no-hang wrapped-stream nil nil))
  -               (initialize-sequence)
  -               (record-history)))
  -          (unless results
  -            (initialize-sequence))
  -          (tagbody
  -           start
  -             (restart-case
  -                 (progn
  -                   (do-while-popf (value results)
  -                     (record-history)
  -                     (emit value))
  -                   (stop))
  -               (ignore-command ()
  -                 (reset-token-sequence)
  -                 (go start))
  -               (die ()
  -                 (exit 1)))))))))
  +                               (logging-evaluation-form-sequence x))))
  +         (reset-token-sequence ()
  +           (loop :while (read-char-no-hang wrapped-stream nil nil))
  +           (initialize-sequence)
  +           (record-history)))
  +      (initialize-sequence)
  +      (tagbody
  +       restart
  +         (restart-case
  +             (do-while-popf (value results)
  +               (record-history)
  +               (return-from shell-read value))
  +           (give-up-on-read ()
  +             (reset-token-sequence)
  +             (go restart))))
  +      (if eof-error-p
  +          (error 'shell-eof)
  +          eof-value))))
  +
  +(defun %shell-repl (stream history)
  +  (let ((last-result (list (truthy-exit-info))))
  +    (labels
  +        ((handle-parse-failure (e)
  +           (when-let ((restart (find-restart 'ignore-command)))
  +             (format *error-output* "Parse error: ~A~%" e)
  +             (invoke-restart restart)))
  +         (handle-shell-eof (e)
  +           (declare (ignore e))
  +           (return-from %shell-repl (values-list last-result)))
  +         (read-with-handlers ()
  +           (handler-bind
  +               ((parse-failure #'handle-parse-failure)
  +                (shell-eof #'handle-shell-eof))
  +             (shell-read stream :history history)))
  +         (eval-with-restarts (form)
  +           (restart-case
  +               (eval form)
  +             (give-up-on-eval ()
  +               (falsey-exit-info)))))
  +      (declare (dynamic-extent #'handle-parse-failure)
  +               (dynamic-extent #'handle-shell-eof)
  +               (dynamic-extent #'read-with-handlers)
  +               (dynamic-extent #'eval-with-restarts))
  +
  +      (loop
  +        (let* ((form (read-with-handlers))
  +               (result (multiple-value-list (eval-with-restarts form))))
  +          (debug-log status "RESULT: ~A" result)
  +          (setf last-result result))))))
  +
  +(defun shell-repl (stream &key history)
  +  (loop
  +    (restart-case
  +        (return (%shell-repl stream history))
  +      (exit-repl ()
  +        (return (falsey-exit-info)))
  +      (restart-repl ()))))
   
   (defparameter *debug* nil)
   (defparameter *help* nil
  
positive.code:   (completion-suggestions-for-input input-string cursor-position *shell-readtable*))
  
  (defun logging-token-sequence (stream)
    "Return an iterator that produces the tokens found in `stream'.
  
  Tokens are read using `*shell-readtable*'."
    (lazy-map (tokens-in-stream-symbolic-readtable stream '*shell-readtable*)
  
negative.code:               (startup-file (probe-file "~/.shclrc.lisp")))
            (when startup-file
              (load startup-file))
  
            (handler-case
                (shell-repl stream :history h)
              (exit-condition (e)
                (exit-condition-exit-info e))))))))
  