repl: Use exception handling.

* module/mes/repl.mes (repl): Use catch to prevent exit upon error.
This commit is contained in:
Jan Nieuwenhuizen 2016-12-28 20:49:19 +01:00
parent cb1fa49767
commit 1f9476aeca

View file

@ -159,23 +159,29 @@ along with Mes. If not, see <http://www.gnu.org/licenses/>.
(force-output) (force-output)
(let ((sexp (read-env a))) (let ((sexp (read-env a)))
(when (not (eq? sexp '())) (when (not (eq? sexp '()))
(when print-sexp? (catch #t
(display "[sexp=") (lambda ()
(display sexp) (when print-sexp?
(display "]") (display "[sexp=")
(newline)) (display sexp)
(cond ((and (pair? sexp) (eq? (car sexp) (string->symbol "unquote"))) (display "]")
(let ((r (meta (cadr sexp) a))) (newline))
(if (pair? r) (loop (append r a)) (cond ((and (pair? sexp) (eq? (car sexp) (string->symbol "unquote")))
(loop a)))) (let ((r (meta (cadr sexp) a)))
((and (pair? sexp) (eq? (car sexp) 'mes-use-module)) (if (pair? r) (loop (append r a))
(loop (mes-load-module-env (cadr sexp) a))) (loop a))))
(else (let ((e (eval sexp a))) ((and (pair? sexp) (eq? (car sexp) 'mes-use-module))
(if (eq? e *unspecified*) (loop a) (loop (mes-load-module-env (cadr sexp) a)))
(let ((id (string->symbol (string-append "$" (number->string count))))) (else
(set! count (+ count 1)) (let ((e (eval sexp a)))
(display id) (if (eq? e *unspecified*) (loop a)
(display " = ") (let ((id (string->symbol (string-append "$" (number->string count)))))
(display e) (set! count (+ count 1))
(newline) (display id)
(loop (acons id e a)))))))))))) (display " = ")
(display e)
(newline)
(loop (acons id e a))))))))
(lambda (key . args)
(format (current-error-port) "exception: ~a ~a\n" key args)
(loop a))))))))