Re: STk 2.2 -> 3.0 porting: problems with menu

From: Erick Gallesio <eg_at_kaolin.unice.fr>
Date: Wed, 11 Oct 1995 19:26:49 +0000

> I started to port all the code I have developed using STk 2.1.6 to the new
> STk 3.0. While there were no problems in integrating my own extensions, I
> cannot understand how to port the following code:
>
> (define (test menubut label callBack)
> (menu-add menubut 'command :label label
> :command `(begin
> (format uk-ciw-log "M> ~a > ~a\n" ,menubut ,label)
> ,callBack)))
>
> The problem is that I need to define functions that build call-backs (for
> menus, for buttons, for widget bindings...).
>

One simple way consists to write the following code:
        (define (test menubut label callBack)
          (menu-add menubut 'command :label label
                     :command (lambda ()
                                (format uk-ciw-log "M> ~a > ~a\n"
                                        menubut label)
                                callBack)))))

In fact, you can now use closures which capture the variables you use in your command when you evaluate the lambda expression. BTW, old form (i.e. using a
list) should continue to work, since I have left it to assure (some) portability of old applications). Do you have problems with it?

However, I don't understand the use of callBack at the end of your command,
since the result is "disgarded" when the lambda is evaluated.



                -- Erick
Received on Wed Oct 11 1995 - 19:26:50 CET

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST