Introduction to the Tcl Programming Language


Table of Contents:

  1. Course Availability
  2. Course Prerequisites
  3. Emacs Tutorial
  4. Course Schedule and Location
  5. Tentative Draft Syllabus
  6. Exercises
  7. Texts
  8. Resources
  9. An Overview of the Tcl Programming Language

Course Availability

This course is being offered internally to U. of C. Library Systems staff only.

Course Prerequisites

Emacs Tutorial

On Tuesday 12 July 1994, I will offer a tutorial introduction to the Emacs text editor to anyone who would like to attend. The tutorial will be held in BSLC-018, the lab-like classroom in the basement of the Biological Sciences Learning Center.

Course Schedule and Location

Lectures for the course will be Tuesday-Thursday, 3:00-4:30. The first class will be 14 July 1994. The course will last approximately eight to ten weeks.

Classes will be held in BSLC-018, with the exception of 21 July and 2 August, when the room is busy. On these two days we will meet in JRL-124.

Tentative Draft Syllabus

The course will cover basic Extended Tcl programming, with coverage of simple Expect programming, Tcl-DP, and some very minimal exposure to Tk. This syllabus is subject to change, and depending on the speed at which the course progresses, we may not get to cover everything listed: in other words, we won't rush the course.
  1. Introduction and Overview
  2. Tcl Syntax: quoting and substitution
  3. Expressions
  4. Variables: simple variables; associative arrays
  5. Lists; Keyed Lists
  6. Control Structures: built-ins
  7. Procedures; Recursion
  8. The Unix File System
  9. Files and I/O
  10. Strings
  11. Regular Expressions
  12. Writing Applications; Autoloading; Timing; Profiling
  13. Processes
  14. Error Handling; Defining Control Structures; Exceptions
  15. Client / Server; Distributed Programming
  16. Expect

Exercises

  1. Exercise #1
  2. Exercise #2
  3. Exercise #3
  4. Exercise #4

Future Courses

Future courses, if we should decide to offer them, could cover:

Texts

Required Reading

The text for the course is:
John K. Ousterhout. Tcl and the Tk Toolkit. Reading, MA: Addison-Wesley, 1994. $42.50.

We won't be going through the entire text, only the first 140 pages out of 437, but the rest of the book will be used if we do further courses on Tcl and Tk.

Recommended Reading

The following manual pages, conference papers and miscellaneous texts will be referred to during the course. All of these are available online or for printing.

Resources

Tcl is well supported on the Net. Here are some resources:
Usenet Newsgroup
Frequently Asked Questions
Maintained by Larry Virden lvirden@cas.org.
WWW Tcl/Tk Resources
Source Code Repository
TCL Manual Pages
Extended Tcl (TclX) Manual Page

An Overview of the Tcl Programming Language

Tcl (pronounced Tickle) is a general purpose programming language originally intended to be embedded in other applications as a configuration and extension language. The success of one its most important embeddings, the Tk toolkit for the X Windows System, has resulted in Tcl and Tk together being most heavily used for building graphical user interfaces (GUIs). It is also heavily used as a scripting language like Awk, Perl or Rexx, and (as Expect) is used to script interactive applications (e.g., to automate telnet logins to various information vendors).

Here in Library Systems at The University of Chicago we already use Tcl:

In addition, a number of our Unix applications are written in Tcl (see below), and Tcl is the programming language of the University of Chicago BSDAC Phoenix Project.

Tcl is a successful language:

The Tcl/Tk developer community now numbers in the tens of thousands and there are thousands of Tcl applications in existence or under development. The application areas for Tcl and Tk cover virtually the entire spectrum of graphical and engineering applications, including computer-aided design, software development, testing, instrument control, scientific visualization, and multimedia. [...] Tcl and Tk are being used by hundreds of companies, large and small, as well as universities and research laboratories.[1]
The companies using Tcl include SCO, Digital, Cray, AT&T, and Sun Microsystems. John Ousterhout, the designer of Tcl/Tk, has recently moved to Sun Microsystems from UC Berkeley to head up a group dedicated to Tcl/Tk; he has made some comments on Tcl's future at Sun. There is an annual international Tcl conference which has been held twice so far, and a safe variant of Tcl has been proposed as the language for Enabled Mail in the Internet Multimedia Mail standard (RFC 1341).

Tcl is virtually unique in the combination of features it offers:

Scripting Language
Tcl is a powerful scripting language that runs under Unix, Linux, VMS, DOS/Windows, OS/2, and MacOS (at least). It provides all the usual high-level programming features that we've come to expect from languages like the Unix shell, Awk, Perl, or Rexx, such as:
Embeddability
Tcl is a small language designed to be embedded in other applications (C programs for example) as a configuration and extension language. This minimizes the number of languages that users need to learn in order to configure their applications, and makes these applications programmable with no extra effort. In addition, Tcl is a complete and well-designed programming language, whereas many existing configuration languages were designed (to be kind) in an ad hoc manner.
Extensibility
Tcl is specially designed to make it extremely easy to extend the language by the addition of new primitives in C. These new primitives are truly first-class citizens of the language, sharing the same error handling and memory management as the original primitives. This has led to many useful extensions, such as DBMS access (extensions exist for Oracle, Sybase, Ingres, Postgres and many other DBMS's), SNMP, Motif, etc. In addition, this allows Tcl programs to be optimized by moving time critical code into C.
Equivalence of Data and Programs
Like Lisp, Tcl uses the same representation for data and for programs. This means that Tcl programs or scripts can be manipulated as data: stored in variables, written to and later read from files or databases, passed from one Tcl program to another across the Internet, etc. In addition, it means that the programmer can create new Tcl control structures or error handling routines as easily as writing a simple function.
Automatic Memory Management
All Tcl data structures are dynamically allocated and fully variable in size. The programmer never needs to allocate memory or specify maximum sizes.
Event-Driven Programming
Tcl supports event-driven programming (required for GUI programming) with the ability to associate Tcl code with any variable or array element (the code is executed automatically whenever the variable is read or written).
IPC Between Multiple Tcl Applications
Tcl supports the passing of Tcl code as messages between Tcl applications running on different machines across the Internet. This allows client-server protocols which incorporate the full power of the Tcl language, and makes it possible to write very tightly-integrated applications.
Program Development Tools
Tcl has a powerful symbolic debugger, timing and profiling tools, language sensitive editing modes for Emacs, a WYSIWYG GUI builder (xf), a real-time application monitor (tkinspect), etc.
Freely Redistributable
The source code for the Tcl language system is freely copyable for any purpose, so it can be used in commercial applications as well as academic applications and freeware.

By virtue of it's extensibility, here are some of the specialized Tcl variants that are widely used; they are readily mixed and matched:

Extended Tcl
Extended Tcl adds primitives to the core Tcl distribution. Some of the primitives include: Unix system calls, time and date parsing, Awk-like pattern matching in files, keyed lists (structs), profiling commands, TCP/IP commands, etc.
The Tk Toolkit
Tk is a Tcl embedding of Ousterhout's Tk toolkit for the X Window System. With Tk, the Tcl programmer can create GUI applications in a fraction of the time and code required if programming in a low-level language like C. There is also a very full-featured GUI builder for Tk called xf which allows you to build live interfaces without writing any code.
The Expect Scripting Language
Expect extends Tcl to allow scripts to control interactive applications which can't otherwise be programmed. It is similar to the scripting languages found in software terminal emulators like Crosstalk and Kermit, but isn't restricted to scripting access to communications ports.
The [incr tcl] Object Oriented Extension
[incr tcl][2] adds sophisticated object-oriented programming features to Tcl, including multiple inheritance.
Tcl Distributed Programming (Tcl-DP)
Tcl-DP adds a native (i.e., Tcl-based) remote procedure call interface to Tcl that makes it possible to write tightly-coupled networked applications. Using Tcl-DP, an application running on a machine elsewhere on the Internet can respond automatically to the modification of a variable in a local application.
GroupKit for Groupware
Groupkit is a groupware toolkit designed to make it "easy" to develop multi-user applications for real-time distributed desk-top conferencing. The philosophy is that groupware development should be only slightly more difficult to code than single-user programs.
Safe-Tcl
Designed primarily for Enabled Mail applications, in which electronic mail messages can contain "live" code to be executed automatically when received, Safe-Tcl is a Tcl interpreter that doesn't allow any "unsafe" commands to be executed -- commands that might delete files or otherwise destroy valuable data. It can be used in any distributed application.

Here are few example Tcl and Tk applications (as opposed to the extensions above), most of which we run on our system:

ical
A shared calendar manager.
beth
An embeddable GUI text editor.
tkman
A manual page browser.
point
A full-featured text editor.
Deja GNU
Generalized regression testing software.
exmh
GUI-based multimedia email system.
tkined
Interactive GUI network editor and SNMP programmer.
moog
A gopher client.
zircon
Internet Relay Chat client.

End Notes

  1. Ousterhout, Tcl and the Tk Toolkit, p. xviii.
  2. [incr tcl] is a pun on C++: "[incr tcl]" is the Tcl idiom for incrementing a variable.

Keith Waclena
This page last updated: Mon Jul 25 18:22:57 CDT 2005