[plt-scheme] handling user-breaks in MrEd app...

From: Robert Bruce Findler (robby at cs.uchicago.edu)
Date: Wed Oct 30 20:10:14 EST 2002

To answer your technical question, the exception handler isn't being
set on the right thread (they don't move over automatically). You want
this:

  (thread (lambda ()
            (with-handlers ...
              (read-eval-print-loop))))

Also, you might want to use thread-wait instead of that busy loop.

As I wrote before, to do this properly you really want to do what
DrScheme does (the break button (also kills if necessary), source
location error highlighting, stack traces, profiling support, the
module language, bound variable renaming (aka "alpha renaming") ... the
list goes on). 

Being the masochist that I am, let me ask: why aren't you using
DrScheme?

Robby

At Wed, 30 Oct 2002 17:58:45 -0600, Jefferson Provost wrote:
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 
> 
> Hey,
> 
> I'm writing a graphical MrEd app, and though most interaction will be 
> through graphical objects, I want to run a repl for debugging and other 
> stuff.  I don't want to use MrEd's graphical repl, but when I do mred 
> -z, the stdio repl never yields to give events/time to my graphical 
> objects.  My solution is to instantiate my graphical objects, and then 
> run a stdio repl in a separate, as in the code below.
> 
> The problem is that the with-handlers form seems to swallow all 
> exceptions (other than exn:break) without any notification.  Without the 
> with-handlers, breaks (ctrl-C's) send the program into some inscrutable 
> state in which there's still a repl running (the top-level repl?) but 
> the program is basically unusable.
> 
> I guess I don't understand how handlers work, because I assumed that 
> handling one kind of exception wouldn't change how the others were 
> handled, but that's not what's happening.  What's going on?
> 
> J.
> 
> ;;;;;;;;;;;;;;;;;;;;;;;
>    (define (gui-repl)
>      (let ((t (thread read-eval-print-loop)))
>        (let loop ()
> 	(yield)
> 	(sleep 0.01)
> 	(if (thread-running? t) (loop)))))
> 
> ;;;;;;;;;;;;;;;;;;;;;;
> ; instantiate my window(s) here
> 
> (define my-console (instantiate my-graphical-console% () )
> (send my-console show #t)
> 
> ;;;;;;;;;;;;;;;;;;;;;
> ; start the repl
>    (with-handlers ((exn:break? (lambda (x)
>    			       (display (format "\nuser break!\n"))
>   	 
> 	       (exit))))
>    	       (gui-repl)
>    	       (exit))
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> 
> 
> The problem with this is that errors generated from my-console (or the 
> windows it spawns) just vanish.  If I run mred w/o "-z", and comment out 
> everything below ";start the repl", then errors get printed to stdout



Posted on the users mailing list.