clTcl Concepts

Home Installation Manual Examples Specification

The clTcl package embeds Tcl/Tk in Common Lisp. It parses Tcl scripts into lists of strings. These strings are properly escaped so they can be send to a Tcl/Tk interpreter. The package provides an interface to launch Tcl/Tk and setup a two-way stream for communication. Finally it provides synchronized communication between Lisp and Tcl/Tk.

Embedded Tcl

Tcl scripts are parsed into list of strings. Just like Lisp, Tcl has a uniform syntax that is easily parsed. A Tcl script is a list of commands. The script is read and every command becoms a properly escaped string.

Reader macro #TCL[] reads the Tcl script between square brackets.

Running Tcl/Tk

A running clTcl program is a Lisp process and a Tcl/Tk process that communicate via a two-way stream. Launching Tcl/Tk is implementation dependent. The stream is available via global *stream*.

The event loop

The event-loop is synchronized with Tcl/Tk's event loop. There is a single flow of control that switches back and forth between Lisp and Tcl/Tk.

The event-loop starts a Tcl/Tk process, loads the given script and starts listening for events. When the user exits the application the event-loop terminates and so does the application.

The typical flow of control during a cycle in the event loop is

  1. A Tcl procedure gets triggered by a user action.
  2. If the Lisp side needs to be involved it is called with Tcl proc callLisp. It calls a function on the Lisp side and waits for a result.
  3. The called Lisp function does its business. If needed it calls Tcl/Tk. When the Lisp function is done its return value gets passed back to Tcl/Tk. The event finishes and Tcl/Tk waits for the next one.