Introduction to the Tcl Programming Language
Table of Contents:
- Course Availability
- Course Prerequisites
- Emacs Tutorial
- Course Schedule and Location
- Tentative Draft Syllabus
- An Overview of the Tcl Programming Language
This course is being offered internally to U. of C. Library Systems
- Some previous programming experience.
- Working knowledge of any Unix text editor (emacs, vi, axe, etc).
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
the lab-like classroom in the basement of the Biological Sciences
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
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.
- Introduction and Overview
- Tcl Syntax: quoting and substitution
- Variables: simple variables;
- Lists; Keyed Lists
- Control Structures: built-ins
- Procedures; Recursion
- The Unix File System
- Files and I/O
- Regular Expressions
- Writing Applications; Autoloading; Timing; Profiling
- Error Handling; Defining Control Structures; Exceptions
- Client / Server; Distributed Programming
- Exercise #1
- Exercise #2
- Exercise #3
- Exercise #4
Future courses, if we should decide to offer them, could cover:
- Basic Tk Progamming
- Object Oriented Programming with [incr tcl]
- Embedded Programming with Tcl (including extensions)
- Advanced Tcl/Tk Programming
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.
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.
- John K. Ousterhout. The Tcl Reference Manual. Online
- Karl Lehenbauer and Mark Diekhans. Extended Tcl. Online
- Don Libes. "A Debugger for Tcl Applications" in Proceedings of
the Tcl/Tk Workshop. Berkeley: The University of California, 1993.
- Don Libes. "expect: Curing Those Uncontrollable Fits of
Interaction" in Proceedings of the Summer USENIX Conference.
Anaheim, CA: Usenix Association, 1990.
- Brian C. Smith, Lawrence A. Rowe and Stephen C. Yen. "Tcl
Distributed Programming" in Proceedings of the Tcl/Tk Workshop.
Berkeley: The University of California, 1993.
- Brent Welch. Notes on Quoting.
Tcl is well supported on the Net. Here are some resources:
- Usenet Newsgroup
- Frequently Asked Questions
- Maintained by Larry Virden email@example.com.
- 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
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.
- as a general-purpose scripting language to write Unix applications;
- to automate login scripts for telnet connections;
- as the programming language for the Reserve System.
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.
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
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:
- Variable-length strings
- Associative arrays
- Keyed lists (aka structs, structures or records)
- Pattern matching with regular expressions
- Ability to define or redefine procedures at run-time
- Full file access
- Error handling
- Tcl is a small language designed to be embedded in other
applications (C programs for example) as a configuration and extension
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.
- 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
- 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
- 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
- The [incr tcl] Object Oriented Extension
- [incr tcl] adds sophisticated
object-oriented programming features to Tcl, including multiple
- 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.
- 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:
- A shared calendar manager.
- An embeddable GUI text editor.
- A manual page browser.
- A full-featured text editor.
- Deja GNU
- Generalized regression testing software.
- GUI-based multimedia email system.
- Interactive GUI network editor and SNMP programmer.
- A gopher client.
- Internet Relay Chat client.
and the Tk Toolkit, p. xviii.
[incr tcl] is a pun on C++: "[incr tcl]" is
the Tcl idiom for incrementing a variable.
This page last updated: Mon Jul 25 18:22:57 CDT 2005