diff options
author | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2009-02-08 14:16:05 +0100 |
---|---|---|
committer | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2009-02-08 14:16:05 +0100 |
commit | e16e29baa9d444be4fd5e60f93c124c666c60b80 (patch) | |
tree | 77f8bd13c48ce8ddb69bb1f04d4af3ba19b46fb2 /scheme/geiser | |
parent | 3670817dcc482c75105da7965e7306044171b0d9 (diff) | |
download | geiser-guile-e16e29baa9d444be4fd5e60f93c124c666c60b80.tar.gz geiser-guile-e16e29baa9d444be4fd5e60f93c124c666c60b80.tar.bz2 |
Capturing output of scheme evaluations
Diffstat (limited to 'scheme/geiser')
-rw-r--r-- | scheme/geiser/eval.scm | 12 |
1 files changed, 8 insertions, 4 deletions
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 . <form-value>)) +The result is a list of the form ((RESULT . <form-value>) (OUTPUT . <string>)) if no evaluation error happens, or ((ERROR (KEY . <error-key>) <error-arg>...)) 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)) |