10.41.5 Putting It All Together

At this point we now know Tcl, the Tk extensions, and how they can be integrated into SICStus Prolog through the tcltk library module. The next problem is how to get all this to work together to produce a coherent application. Because Tcl can make Prolog calls and Prolog can make Tcl calls it is easy to create programming spaghetti. In this section we will discuss some general principles of organizing the Prolog and Tcl code to make writing applications easier.

The first thing to do is to review the tools that we have. We have two programming systems: Prolog and Tcl/Tk. They can interact in the following ways:

With these interaction primitives there are three basic ways in which Prolog and Tcl/Tk can be organized:

  1. Tcl the master, Prolog the slave: program control is with Tcl, which makes occasional calls to Prolog, through the prolog function.
  2. Prolog the master, Tcl the slave: program control is with Prolog, which makes occasional call to Tcl through the tcl_eval function
  3. Prolog and Tcl share control: program control is shared with Tcl and Prolog interacting via the Prolog event queue, through tcl_event, tk_next_event, and prolog_event.

These are three ways of organizing cooperation between Tcl/Tk and Prolog to produce an application. In practice an application my use only one of these methods throughout, or may use a combination of them where appropriate. We describe them here so that the developer can see the different patterns of organization and can pick those relevant to their application.


Send feedback on this subject.