Alternate guard form - evaluate the guard clauses in the continuation of the raise.

We need to override the current-exception-handler and still pass a thunk to be
applied on return, but this allows us to print stack traces inside guards.
This commit is contained in:
Alex Shinn 2013-04-03 00:18:58 +09:00
parent af8aed4c5a
commit 0f723c17ea

View file

@ -923,22 +923,26 @@
(define-syntax guard
(syntax-rules ()
((guard (var clause ...) e1 e2 ...)
(let ((orig-handler (current-exception-handler)))
((call-with-current-continuation
(lambda (guard-k)
(with-exception-handler
(lambda (condition)
((call-with-current-continuation
(lambda (handler-k)
(guard-k
(let* ((var condition) ; clauses may set! var
(res
(with-exception-handler
orig-handler
(lambda ()
(let ((var condition))
(guard-aux (handler-k (lambda ()
(guard-aux
(handler-k (lambda ()
(raise-continuable condition)))
clause ...))))))))
clause ...)))))
(guard-k (lambda () res)))))))
(lambda ()
(call-with-values (lambda () e1 e2 ...)
(lambda args
(guard-k (lambda () (apply values args)))))))))))))
(let ((res (begin e1 e2 ...)))
(guard-k (lambda () res))))))))))))
(define-syntax guard-aux
(syntax-rules (else =>)