Re: Tk 4 bindings and Scheme

From: Erick Gallesio <eg_at_kaolin.unice.fr>
Date: Wed, 29 Nov 1995 10:04:11 +0000

> Erik Ostrom writes
> .....
>
> In Tcl, if you want to short-circuit the multiple bindings, you can have
> the binding that gets run first use a `break' statement. This will not
> only exit from the script it's running, but also stop Tk from running
> the rest of the bindings it finds for the event. However, Scheme (and
> therefore STk) has no `break' statement.
>
> Has anyone else had this problem? Is there a good way to deal with it?

The current solution consists to have a binding which return the symbol 'break.
When the break symbol is encountered, the bindings which remain to execute are
left of.
The following example show this:
  (button '.b1 :text "Button1" :command (lambda () (display "In callback\n")))
  (button '.b2 :text "Button2" :command (lambda () (display "In callback\n")))
  (pack .b1 .b2)

  (bind .b1 "<1>" (lambda()
                    (display ".b1 binding\n")
                    'break))
  (bind .b2 "<1>" (lambda()
                    (display ".b2 binding\n")))

.b1 will display only one message, whereas .b2 will display both.

BTW, this is not the elegant solution that a Schemer would like. Something
using call/cc would have be probably preferable. However, it obliges to always
pass the current continuation to the callback, which is very costly.
Furthermore, it is difficult to integrate it with the way Tk treats the chain
of events which must be executed.




                -- Erick
Received on Wed Nov 29 1995 - 10:04:11 CET

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