From 0935e89110296b884d06141b5b4386122f18403e Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Sun, 8 Feb 2009 11:56:30 +0100 Subject: Better error presentation. --- scheme/geiser/eval.scm | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'scheme') diff --git a/scheme/geiser/eval.scm b/scheme/geiser/eval.scm index 3e800c9..81b2647 100644 --- a/scheme/geiser/eval.scm +++ b/scheme/geiser/eval.scm @@ -25,18 +25,32 @@ ;;; Code: (define-module (geiser eval) - #:export (eval-in)) + #:export (eval-in) + #:use-module (srfi srfi-1)) (define (eval-in form module-name) "Evals FORM in the module designated by MODULE-NAME. If MODULE-NAME is #f or resolution fails, the current module is used instead. The result is a list of the form ((RESULT . )) -if no evaluation error happens, or ((ERROR ...)) -in case of errors." +if no evaluation error happens, or ((ERROR (KEY . ) ...)) +in case of errors. Each error arg is a cons (NAME . VALUE), where NAME includes +SUBR, MSG and REST." (let ((module (or (and module-name (resolve-module module-name)) (current-module)))) (catch #t (lambda () (list (cons 'result (eval form module)))) - (lambda (key . args) (list (cons 'error (cons key args))))))) + (lambda (key . args) + (list (cons 'error (apply parse-error (cons key args)))))))) + +(define (parse-error key . args) + (let* ((len (length args)) + (subr (and (> len 0) (first args))) + (msg (and (> len 1) (second args))) + (margs (and (> len 2) (third args))) + (rest (and (> len 3) (fourth args)))) + (list (cons 'key key) + (cons 'subr (or subr '())) + (cons 'msg (if msg (apply format (cons #f (cons msg margs))) '())) + (cons 'rest (or rest '()))))) ;;; eval.scm ends here -- cgit v1.2.3