From 571fa0993c2b191d9b2e75a855f45400fed7e81a Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Tue, 23 Feb 2016 04:03:59 +0900 Subject: [PATCH] improve repl error message --- contrib/60.repl/repl.scm | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/contrib/60.repl/repl.scm b/contrib/60.repl/repl.scm index 698c77c5..f358daa5 100644 --- a/contrib/60.repl/repl.scm +++ b/contrib/60.repl/repl.scm @@ -36,6 +36,34 @@ (picrin macro)) "picrin.user")) + (define (repeat x) + (let ((p (list x))) + (set-cdr! p p) + p)) + + (define (join xs delim) + (cdr (apply append (map list (repeat delim) xs)))) + + (define (string-join strings delim) + (apply string-append (join strings delim))) + + (define (->string x) + (call-with-port (open-output-string) + (lambda (port) + (write x port) + (get-output-string port)))) + + (define (print-error-object e) + (display "error: ") + (display (error-object-message e)) + (display ".") + (define irritants (error-object-irritants e)) + (unless (null? irritants) + (display " (irritants: ") + (display (string-join (map ->string irritants) ", ")) + (display ")")) + (newline)) + (define (repl) (init-env) (let loop ((buf "")) @@ -50,9 +78,7 @@ (lambda (condition) (if (error-object? condition) (unless (equal? (error-object-message condition) "unexpected EOF") - (display "error: ") - (display (error-object-message condition)) - (newline) + (print-error-object condition) (set! str "")) (begin (display "raised: ")