[plt-scheme] streams; event-handling

From: Robby Findler (robby at cs.uchicago.edu)
Date: Wed Apr 12 00:16:59 EDT 2006

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.)


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.