Created: March 15, 1994 —Overview.fm3—Copyright Prentice Hall—DRAFT: 1/13/95
xxviii
constructs and looks somewhat like C. It is also easy to add new Tcl primitives by
writing C procedures. By now there are a large number of Tcl commands that
have been contributed by the Tcl community. So another reason to choose Tcl is
because of what you can access from Tcl scripts “out-of-the-box”. To me, this is
more important than the details of the language.
The Tcl C library has clean interfaces and is simple to use. The library
implements the basic interpreter and a set of core scripting commands that
implement variables, flow control, file I/O, and procedures (see page 15). In addi-
tion, your application can define new Tcl commands. These commands are associ-
ated with a C or C++ procedure that your application provides. The result is that
applications are split into a set of primitives written in a compiled language and
exported as Tcl commands. A Tcl script is used to compose the primitives into the
overall application. The script layer has access to shell-like capability to run
other programs and access the file system, as well as call directly into the appli-
cation by using the application-specific Tcl commands you define. In addition,
from the C programming level, you can call Tcl scripts, set and query Tcl vari-
ables, and even trace the execution of the Tcl interpreter.
There are many Tcl extensions freely available on the net. Most extensions
include a C library that provides some new functionality, and a Tcl interface to
the library. Examples include socket access for network programming, database
access, telephone control, MIDI controller access, and
expect
, which adds Tcl
commands to control interactive programs.
The most notable extension is Tk, a toolkit for X windows. Tk defines Tcl
commands that let you create and manipulate user interface widgets. The script-
based approach to UI programming has three benefits. First, development is fast
because of the rapid turnaround - there is no waiting for long compilations. Sec-
ond, the Tcl commands provide a higher-level interface to X than most standard
C library toolkits. Simple interfaces require just a handful of commands to define
them. At the same time, it is possible to refine the interface in order to get every
detail just so. The fast turnaround aids the refinement process. The third advan-
tage is that the user interface is clearly factored out from the rest of your appli-
cation. The developer can concentrate on the implementation of the application
core, and then fairly painlessly work up a user interface. The core set of Tk wid-
gets is often sufficient for all your UI needs. However, it is also possible to write
custom Tk widgets in C, and again there are many contributed Tk widgets avail-
able on the network.
Ftp Archives
The network archive site for Tcl is
ftp.aud.alcatel.com
. Under the
/tcl
directory there are subdirectories for the core Tcl distributions (
sprite-mirror
,
for historical reasons), contributed extensions (
extensions
), contributed applica-
tions (
code
), documentation (
docs
), and Tcl for non-UNIX platforms (
distrib
).
Mirror sites for the archive include:
ftp://syd.dit.csiro.au/pub/tk/contrib
ftp://syd.dit.csiro.au/pub/tk/sprite