Re: error environment?

From: Erick Gallesio <eg_at_saxo.essi.fr>
Date: Mon, 04 Nov 1996 17:50:02 +0100

> David Fox writes
> Is it possible to write report-error in such a way that I go
> into a repl loop that can see the local variables in the
> environment where the error occurred? Anyone done it?

Hereafter is a procedure that does the job.

   (define (repl-in-env env)
      (letrec ((terminate #f)
               (repl-loop (lambda ()
                            (display ">> ") (flush)
                            (let ((x (read)))
                              (if (eof-object? x)
                                  (set! terminate 0)
                                  (begin
                                    (write (eval x env))
                                    (newline)
                                    (repl-loop)))))))

        (dynamic-wind (lambda () #f)
                      repl-loop
                      (lambda () (unless terminate (repl-in-env env))))
        (newline)))

And a report-error which use it

    (define (report-error head message who)
      (format (current-error-port) "\n~A~A:~S\n" head message who)
      (TRACE "~S" (%get-eval-stack))
      (repl-in-env (caddr (%get-environment-stack))))


The cadddr used here is because when you grab the environments with
%get-environment-stack, you also grab the environments necessary to make
the call, to get-environment-stack .... (I think that cadddr is correct, I have not really tested).



                -- Erick
Received on Mon Nov 04 1996 - 18:01:32 CET

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST