[plt-scheme] Return Value

From: Paul Graunke (ptg at ccs.neu.edu)
Date: Mon Sep 9 10:19:14 EDT 2002

There is no good way to return a value from a callback using a typical
oo/callback based GUI system such as mred's. The control context of the
callback and the control context of the main program are totally
disconnected. You have to use mutable state to communicate the value
and possibly use a semaphore if the code needs to wake up the main
thread when the button is clicked.

The Haskellites at Yale have noticed this problem, too. They use arrows
(a functional programming technique for mimicing imperative features)
to glue together either streams of events or continually varying
signals.  If you're interested, check out their paper.

  Antony Courtney and Conal Elliott. Genuinely functional user
  interfaces. In Proceedings of the 2001 Haskell Workshop, September
  2001.

Paul

P.S.  You can use (instantiate button% () (callback void) ...) if you don't
      want the callback to do anything.

At 09 Sep 2002 02:15:32 +0100, Paulo J. Matos wrote:
>   For list-related administrative tasks:
>     http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 
> Hi all,
> 
> I'm doing a graphical interface that was suggested in my last
> mail to the list.
> Somehow I got myself into a mess.
> 
> I have a function like the following that should return a struct
> of type tran:
> (define read-tran-gui
>  (lambda ()
>     (define rtframe
>       (instantiate frame% ()
>         (label "New Transaction")))
>     ...
> 
> (instantiate button% ()
>       (label "Insert Transaction")
>       (parent rtframe)
>       (callback (lambda (button event) 
>                   (make-new-tran 
>                    (string->number (send tbamount get-value))
>                    (if (eq? (send rad-type get-selection)
>                             0)
>                        *CRED*
>                        *DEB*)
>                    (send tbcomment get-value))
>                   (send rtframe show #f))))
>     
>     (send rtframe show #t)))
> 
> The function needs to return the value returned by make-new-tran
> called in the callback function of the button. How can I do that?
> 
> Best regards,
> 
> -- 
> Paulo J. Matos : pocm(_at_)mega.ist.utl.pt
> Instituto Superior Tecnico - Lisbon    
> Software & Computer Engineering - A.I.
>  - > http://mega.ist.utl.pt/~pocm 
>  ---	
> 	Yes, God had a deadline...
> 		So, He wrote it all in Lisp!
> 




Posted on the users mailing list.