This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: feature?


Mikael Djurfeldt <mdj@mdj.nada.kth.se> writes:

> Install a "lazy-catch" handler which saves the continuation in some
> variable and re-throws the signal.  Then restart using this
> continuation.

The standard signal handler calls scm-error.  This is a problem for
the approach I suggested, since Guile errors aren't restartable.

The following code *should* work.  It doesn't seem to work well,
though.  It might be due to some latent bug in Guile.  It will take
quite a while before I'll get time to look at it.  Maybe someone else
can?

(define restart-continuation #f)

(define (restart)
  (restart-continuation #f))

(define (call-restartably thunk)
  (let ((old-handler #f))
    (dynamic-wind
	(lambda ()
	  (set! old-handler
		(sigaction SIGINT
			   (lambda (sig)
			     (call-with-current-continuation
			      (lambda (c)
				(set! restart-continuation c)
				((car old-handler) sig)))))))
	thunk
	(lambda ()
	  (sigaction SIGINT (car old-handler) (cdr old-handler))))))

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]