Node:Evaluate a Tcl expression and get Prolog events, Next:, Previous:Event functions, Up:Event functions



Evaluate a Tcl expression and get Prolog events

Another way for Prolog to communicate with Tcl is through the predicate tcl_event/3:

     tcl_event(+TclInterpreter, +Command, -Events)
     

This is similar to tcl_eval/3 in that the command Command is evaluated in the Tcl interpreter TclInterpreter, but the call returns a list of events in Events rather than the result of the Tcl evaluation. Command is again a Tcl command represented as a Prolog term in the special Command Format described previously (see Command Format).

This begs the questions what are these events and where does the event list come from? The Tcl interpreters in the SICStus Prolog Tcl/Tk library have been extended with the notion of a Prolog event queue. (This is not available in plain standalone Tcl interpreters.) The Tcl interpreter can put events on the event queue by executing a prolog_event command. Each event is a Prolog term. So a Tcl interpreter has a method of putting Prolog terms onto a queue, which can later be picked up by Prolog as a list as the result of a call to tcl_event/3. (It may be helpful to think of this as a way of passing messages as Prolog terms from Tcl to Prolog.)

A call to tcl_event/3 blocks until there is something on the event queue.

A second way of getting Prolog events from a Prolog event queue is through the tk_next_event/[2,3] predicates. These have the form:

     tk_next_event(+TclInterpreter, -Event)
     tk_next_event(+ListOrBitMask, +TclInterpreter, -Event)
     

where TclInterpreter reference to a Tcl interpreter and Event is the Prolog term at the head of the associated Prolog event queue. (The ListOrBitMask feature will be described below in the Housekeeping section when we talk about Tcl and Tk events; see Housekeeping.).

(We will meet tk_next_event/[2,3] again later when we discuss how it can be used to service Tk events; see Servicing Tk Events).

If the interpreter has been deleted then the empty list [] is returned.