summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChaos Eternal <chaos@shlug.org>2017-08-18 16:27:30 +0800
committerChaos Eternal <chaos@shlug.org>2017-08-18 17:00:32 +0800
commit1bb0a878513ffeac666205b96b92174323322eae (patch)
tree4364ca66a49f2798c0d829f191c60b8e39f89f5f
parent2fb484bac916304c255580fcb9feb3b9cc771ac3 (diff)
downloadgeiser-chez-1bb0a878513ffeac666205b96b92174323322eae.tar.gz
geiser-chez-1bb0a878513ffeac666205b96b92174323322eae.tar.bz2
Handle exceptions of ChezScheme and multi-value as well
- Capture exceptions of ChezScheme - handles multi-value return
-rw-r--r--scheme/chez/geiser/geiser.ss31
1 files changed, 27 insertions, 4 deletions
diff --git a/scheme/chez/geiser/geiser.ss b/scheme/chez/geiser/geiser.ss
index 2fa648c..6568120 100644
--- a/scheme/chez/geiser/geiser.ss
+++ b/scheme/chez/geiser/geiser.ss
@@ -30,11 +30,34 @@
(define (geiser:eval module form . rest)
rest
- (let ((result (if module
- (eval form (environment module))
- (eval form))))
+ (let* ((try-eval (lambda (x . y)
+ (call/cc
+ (lambda (k)
+ (with-exception-handler
+ (lambda (e)
+ (k e))
+ (lambda ()
+ (if (null? y) (eval x)
+ (eval x (car y)))
+ ))))))
+ (result-mid (call-with-values
+ (lambda () (if module
+ (try-eval form (environment module))
+ (try-eval form)))
+ (lambda (x . y)
+ (if (null? y)
+ x
+ (cons x y)))))
+ (result result-mid)
+ (error (if (condition? result-mid)
+ (cons 'error (list
+ (cons 'key
+ (with-output-to-string
+ (lambda () (display-condition result-mid))))))
+ '())))
(write `((result ,(write-to-string result))
- (output . "")))
+ (output . "")
+ ,error))
(newline)))
(define (geiser:module-completions prefix . rest)