Neil Jerram escreveu: >>> Do you think you need to do this in C? (You might do, for reasonable >>> performance - I genuinely don't know yet.) The evaluator already has >>> hooks (see "Evaluator trap options" in the manual) that allow you to >>> call out to arbitrary Scheme code at the entry and exit of every >>> frame. >> [EMAIL PROTECTED] info]$ guile >> guile> (trap-enable 'enter-frame-handler) >> throw from within critical section. >> Abortado >> [EMAIL PROTECTED] info]$ > > Takes effect quickly, doesn't it? :-) > > What you need is something more like this: > > (trap-set! enter-frame-handler > (lambda (key continuation . args) > ...)) > (trap-enable 'enter-frame) > > And it's important to do them in this order.
Hi, perhaps the documentation could be extended to include a small example, such as "The following example demonstrates the use of traps. The program displays each source line as it is executed, by installing a handler that examines the origin of each continuation. The handlers are installed and enabled with @code{trap-set!} and @code{trap-enable}, but they only become active if traps are switched on with @code{(trap-enable 'traps)}. (define (test-add x y) (+ x (/ x y))) (define (record-coverage key continuation . args) (let* ((stack (make-stack continuation)) (frame (stack-ref stack 0)) (source (frame-source frame)) (line (and source (source-property source 'line)))) (if (and line (< line 10)) (format #t "line ~a ~a ~a \n" (1+ line) key args)))) (trap-set! apply-frame-handler record-coverage) (trap-set! enter-frame-handler record-coverage) (trap-set! exit-frame-handler record-coverage) (trap-enable 'apply-frame 'exit-frame 'enter-frame) (trap-enable 'traps) (define z (test-add 1 2)) (trap-disable 'traps) when this is put in a file and executed with --debug, the following is shown line 2 enter-frame (#t (+ x (/ x y))) line 4 enter-frame (#f (/ x y)) line 4 apply-frame (#f) line 4 exit-frame (1/2) line 2 apply-frame (#t) line 2 exit-frame (3/2) " (I'm not sure what the #f / #t mean, though) -- Han-Wen Nienhuys - [EMAIL PROTECTED] - http://www.xs4all.nl/~hanwen _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://lists.gnu.org/mailman/listinfo/guile-devel