[plt-scheme] streams; event-handling

From: Nicholas Chubrich (chubrich at cs.brandeis.edu)
Date: Wed Apr 12 13:34:31 EDT 2006

I presume you are talking about cml.ss in the library?  I also found a 
paper from 2003 on Matthew Flatt's website.
	I'd thought of implementing streams myself, but from skimming the 
paper I gather a naive implementation would possibly break when the window 
is closed, because the stream processing (or the dequeue) might be behind 
what is actually happening.
	On the other hand, I don't see why you couldn't have a streams
system that works exactly like on-event: every object that has an on-event
method has an event stream, and everything that happens between one (cdr
stream) and the next (cdr stream) somehow becomes the body of on-event.  
But I can't quite think how to implement that.  A macro of some sort,

On Tue, 11 Apr 2006, Robby Findler wrote:

> The closest you'd come to that is CML (or cmz), I believe. I'm not sure
> if there is any PLT-specific tutorial introduction to that or if you'd
> have to dig thru the manuals and John Reppy's writings.
> (It does use threads, but I don't consider them overkill.)
> Robby
> At Tue, 11 Apr 2006 22:55:03 -0400 (EDT), Nicholas Chubrich wrote:
> > I've recently been playing with the drawing canvas as a way of getting
> > aquainted with MrEd.  My canvas class draws freehand lines when the
> > left-mouse button is down, and a straight line between two right-clicks.  
> > What bothers me is that the basic control structure is set.  There is a
> > single function on-event that simply runs at the next event, so I have to
> > set a flag in the canvas object to record state; I also have to record
> > previous points, and in a different way depending on what state I am in.  
> > It brings back bad memories of C programming.  My natural instinct is to
> > use an "event stream"; something like this (with a bit of fantasy syntax):
> > 
> > (define (dispatch stream)
> >   (cond ((send (car stream) button-down? 'left)
> >          (draw-free (send (car stream) get-point) (cdr stream)))
> >         ((send (car stream) button-down? 'right)
> >          (draw-straight (send (car stream) get-point) (cdr stream)))
> >         (else (dispatch (cdr stream)))))
> > 
> > (define (draw-straight point stream)
> >   (cond ((send (car stream) button-down? 'right)
> >          (line point (send (car stream) get-point)))
> >         ((or (send (car stream) moving?) (send (car stream) button-up? 'right))
> >          (draw-straight point (cdr stream)))
> >         (else (dispatch stream))))
> > 
> > draw-free would be defined similarly; the key difference is that the
> > recursive call passes (send (car stream) get-point) instead of just point.
> > 	What is the 'PLT way' of structuring an event-driven program in 
> > this spirit?  Is there any way to do it without overkill (threads, for 
> > instance)?  Am I better off just using state changes?  Or am I completely  
> > missing something? 
> > 
> > ---Nick Chubrich.
> > _________________________________________________
> >   For list-related administrative tasks:
> >   http://list.cs.brown.edu/mailman/listinfo/plt-scheme

Posted on the users mailing list.