From e16e29baa9d444be4fd5e60f93c124c666c60b80 Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Sun, 8 Feb 2009 14:16:05 +0100 Subject: Capturing output of scheme evaluations --- scheme/geiser/eval.scm | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'scheme/geiser') diff --git a/scheme/geiser/eval.scm b/scheme/geiser/eval.scm index 81b2647..450221a 100644 --- a/scheme/geiser/eval.scm +++ b/scheme/geiser/eval.scm @@ -31,16 +31,20 @@ (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 . )) +The result is a list of the form ((RESULT . ) (OUTPUT . )) 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 (apply parse-error (cons key args)))))))) + (lambda () + (let* ((result #f) + (output (with-output-to-string + (lambda () (set! result (eval form module)))))) + (list (cons 'result result) (cons 'output output)))) + (lambda (key . args) + (list (cons 'error (apply parse-error (cons key args)))))))) (define (parse-error key . args) (let* ((len (length args)) -- cgit v1.2.3