In a graphical user interface things happen at unpredictable times. A user might for example select a row in a table while the program is communicating with a remote server. These two events may be unrelated, and the order in which they occur might not have particular meaning for the program. Moreover, an interface typically should remain responsive even when the program is waiting for data on some channel. In event-driven programming the program maintains a queue of events that have occurred and responds to those events as it can. Tcl provides an event loop which starts when one calls vwait. Tk itself calls vwait on startup, making it unnecessary for the main script to do it.
There are also conditions that are internal to a program that can be best thought of as being events:
Caveat: there is a difference between these actions, and the 'real' events listed above. Those events happen when the event loop is entered, but the ones listed here happen directly in the processing of the current code. To see what I mean compare when traces on variable writes occur vs. a section of code doing a vwait on the same variable.
What would it take for Tcl's event handling to support user defined events? Perhaps I want to generate events based on encounters of particular tokens during input file parsing, etc. Does this kind of thing currently event? Can one bind to these events so that code gets called automatically upon the raising of a user event?
KBK 2001-08-09: User defined events exist in Tk, but they're limited to UI components. See event with particular attention to event generate. It would be nice to have event bindings on other sorts of things. Michael McLennan's keynote speech at the 2001 Tcl conference put forward a proposal for non-GUI event definitions. Is that on the Web anywhere?
Yes. http://conferences.oreillynet.com/pub/w/10/tcl_presentations.html (That appears to have his paper - but not any of the material from his keynote speech, Dealing with my Tcl addiction, which is where he brought up the notification system with which he and George Howlett had been experimenting.)
trigger is mentioned in one paper - see that page for the PDF of the paper. However, I've not seen where the code itself is available.