[racket] again: timeouts and exceptions

From: Kieron Hardy (kieron.hardy at gmail.com)
Date: Thu Jul 5 15:26:03 EDT 2012

Matthias' comments led me to a couple of articles at Matt Might's site that
have helped me greatly in understanding continuations and escape
continuations. (I also experienced several functional programming "aha
moments" and improved my understanding of exceptions to boot.)

http://matt.might.net/articles/by-example-continuation-passing-style/
http://matt.might.net/articles/implementing-exceptions/

Cheers,

Kieron.


On Thu, Jul 5, 2012 at 12:06 PM, Matthias Felleisen <matthias at ccs.neu.edu>wrote:

>
> 1. I don't know where this prose is but it reads rather confusing.
>
> 2. If I were you, I'd use an escape continuation rather than an exception
> handler here. What you seem to want is flow of control, and let/ec is the
> right tool then.
>
>
>
>
>
> On Jul 5, 2012, at 9:42 AM, Rüdiger Asche wrote:
>
> > Hi there,
> >
> > a few of you recommended to implement timeouting reads via sync/timeout.
> That works neat, but it would be even nicer to combine this w/ exception
> handling, like so:
> >
> >
> > ...
> > ((readbytetimeout)
> >    (lambda (port)
> >            (if (sync/timeout READTIMEOUT inport)
> >              (read-byte inport)
> >              (raise "read-byte" #t))))
> > ...
> > ((readsomething) ..... (readbytetimeout) ......
> >
> >
> > (letrec ((repl (lambda ()
> >              (dosomethingthatmustexecuteperiodically)
> >                (let ((readresult
> >                     (call-with-exception-handler HandlerFn
> >                       (readsomething))))
> >                (repl)))))
> > (repl))
> >
> > Iow, I want the REPL to always be operational but restart from the
> beginning when the innermost read timeouts so that the periodic
> computations get their turn.
> >
> > I didn't get this to work though because according to the docs, "If the
> > exception handler returns a value when invoked by raise, then raise
> > propagates the value to the “previous” exception handler (still in the
> > dynamic extent of the call to raise, and under the same barrier, if
> any)."
> >
> > That is true; I get thrown back out of the entire thing because the
> default uncaught exception handler is called. What ectually does it mean
> "IF the
> > exception handler..." How is it possible for a function NOT to return a
> value?
> > Any return value including #f and () will propagate the exception to the
> > default handler; I simply want to stop it where it is.
> >
> > What do I need to do (or paraphrased: What is the necessary
> implementation of HandlerFn) in order to get this to work? Or do I need yet
> another control flow or handling mechanism?
> >
> > Thanks!
> >
> >
> >
> > ____________________
> > Racket Users list:
> > http://lists.racket-lang.org/users
>
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120705/556ffaf7/attachment-0001.html>

Posted on the users mailing list.