[plt-scheme] Return Value

From: Paul Graunke (ptg at ccs.neu.edu)
Date: Tue Sep 10 12:39:01 EDT 2002

You can still build a dialog like the one you want, but you need to use
mutation to communicate the value from the callback to the rest of the
code. The Dialog% class already blocks the creating thread until the
dialog closes.

If you just want to confim a choice using a dialog, see if the function
  get-choices-from-user
will do what you want.


Paul

At 10 Sep 2002 16:58:10 +0100, Paulo J. Matos wrote:
> 
> > 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.
> 
> This is really a bad problem.
> Sometimes people need to re-check their decisions so I was
> creating a predicate that would show a yes/no radio-box and a
> button. If when the button is clicked, the radio-box is on Yes we
> return #t otherwise #f. 
> 
> Since we cannot return values from callbacks I imagine that it
> would be a lot of work to implement something like this... right?
> 
> Any ideas?
> 
> Best regards,
> 
> Paulo
> 
> > 
> > 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!
> > > 
> > 
> > 
> 
> -- 
> 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.