There are more than 200 examples that total about 5000 lines of Tcl and 2400 lines of C. The sources for the examples are included on a floppy disk with the book.
1.1 The "Hello, World!" example. 3 1.2 Tcl variables. 4 1.3 Command substitution. 4 1.4 Simple arithmetic. 5 1.5 Nested commands. 5 1.6 Built-in math functions. 6 1.7 Controlling precision with tcl_precision. 6 1.8 Quoting special characters with backslash. 6 1.9 Continuing long lines with backslashes. 7 1.10 Grouping with double quotes vs. braces. 7 1.11 Defining a procedure. 8 1.12 A while loop. 9 1.13 Embedded command and variable substitution. 10 1.14 Embedded variable references. 11 1.15 Using /bin/sh to run a Tcl script. 12 2.1 Comparing strings. 21 2.2 Using regular expressions to parse a string. 27 3.1 Using set to return a variable value. 30 3.2 Using info to determine if a variable exists. 30 3.3 Constructing a list with the list command. 32 3.4 Using lappend to add elements to a list. 32 3.5 Using concat to splice together lists. 33 3.6 Double quotes compared to the list command. 33 3.7 Modifying lists with linsert and lreplace. 34 3.8 Deleting a list element by value. 34 3.9 Sorting a list using a comparison function. 35 3.10 Use split to turn input data into Tcl lists. 35 3.11 Using arrays. 36 3.12 Referencing an array indirectly. 37 3.13 Converting from an array to a list. 38 4.1 A conditional if-then-else command. 40 4.2 Chained conditional with elseif. 40 4.3 Using switch for an exact match. 41 4.4 Using switch with substitutions in the patterns. 42 4.5 Using switch with all pattern body pairs grouped with quotes. 42 4.6 Comments in switch commands. 42 4.7 Looping with foreach. 43 4.8 Parsing command line arguments. 43 4.9 Using list with foreach. 43 4.10 A while loop to read standard input. 44 4.11 A for loop. 44 4.12 A standard catch phrase. 45 4.13 A longer catch phrase. 46 4.14 Raising an error. 46 4.15 Preserving errorInfo when calling error. 47 4.16 Specifying errorInfo with return. 47 5.1 Default parameter values. 50 5.2 Variable number of arguments. 50 5.3 Variable scope and Tcl procedures. 51 5.4 A random number generator. 52 5.5 Using arrays for global state. 53 5.6 Print variable by name. 54 5.7 Improved incr procedure. 54 5.8 Using an array to implement a stack. 55 6.1 Using list to construct commands. 58 6.2 Using eval with $args. 59 7.1 Using exec on a process pipeline. 64 7.2 Comparing file modify times. 66 7.3 Creating a directory recursively. 67 7.4 Determining if pathnames reference the same file. 67 7.5 Opening a file for writing. 68 7.6 Opening a file using the POSIX access flags. 69 7.7 A more careful use of open. 70 7.8 Opening a process pipeline. 70 7.9 Prompting for input. 71 7.10 A read loop using gets. 71 7.11 A read loop using read and split. 71 7.12 Finding a file by name. 73 7.13 Printing environment variable values. 74 8.1 Printing a procedure definition. 77 8.2 Getting a trace of the Tcl call stack. 78 8.3 Tracing variables. 79 8.4 Creating array elements with array traces. 80 8.5 Interactive history usage. 81 8.6 Implementing special history syntax. 82 8.7 A Debug procedure. 83 9.1 Maintaining a tclIndex file. 90 9.2 Loading a tclIndex file. 92 10.1 "Hello, World!" Tk program. 97 11.1 Logging the output of a UNIX program. 104 11.2 A browser for the code examples in the book. 109 11.3 A Tcl shell in a text widget. 113 12.1 Two frames packed inside the main frame. 116 12.2 Turning off geometry propagation. 116 12.3 A horizontal stack inside a vertical stack. 117 12.4 Even more nesting of horizontal and vertical stacks. 117 12.5 Mixing bottom and right packing sides. 118 12.6 Filling the display into extra packing space. 119 12.7 Using horizontal fill in a menubar. 120 12.8 The effects of internal padding (-ipady). 121 12.9 Button padding vs. packer padding. 121 12.10 The look of a default button. 122 12.11 Resizing without the expand option. 123 12.12 Resizing with expand turned on. 123 12.13 More than one expanding widget. 124 12.14 Setup for anchor experiments. 124 12.15 The effects of non-center anchors. 125 12.16 Animating the packing anchors. 125 12.17 Controlling the packing order. 126 12.18 Packing into other relatives. 127 13.1 Bindings on different binding tags. 135 13.2 Output from the UNIX xmodmap program. 141 13.3 Emacs-like binding convention for Meta and Escape. 142 14.1 A troublesome button command. 146 14.2 Fixing the troublesome situation. 147 14.3 A button associated with a Tcl procedure. 148 14.4 Radiobuttons and checkbuttons. 150 14.5 A command on a radiobutton or checkbutton. 151 14.6 A menu sampler. 154 14.7 A simple menu-by-name package. 159 14.8 Adding menu entries. 159 14.9 A wrapper for cascade entries. 160 14.10 Using the menu-by-name package. 160 14.11 Keeping the accelerator display up-to-date. 161 15.1 Reading an option database file. 165 15.2 A file containing resource specifications. 166 15.3 Using resources to specify user-defined buttons. 167 15.4 ButtonResources defines buttons based on resources. 168 15.5 Using ButtonResources. 168 15.6 Specifying menu entries via resources. 169 15.7 Defining menus from resource specifications. 170 16.1 A label that displays different strings. 173 16.2 The message widget formats long lines of text. 175 16.3 Controlling the text layout in a message widget. 176 16.4 A scale widget. 177 16.5 A text widget and two scrollbars. 181 17.1 A command entry. 186 17.2 A listbox with two scrollbars. 191 17.3 A listbox with scrollbars and better alignment. 192 17.4 Choosing items from a listbox. 196 18.1 Setting focus-follows-mouse input focus model. 205 18.2 A simple dialog. 207 18.3 A feedback procedure. 209 18.4 A file selection dialog. 210 18.5 Specifying attributes with X resources. 212 18.6 Event bindings for the dialog. 213 18.7 Listing a directory for fileselect. 214 18.8 Accepting a file name. 216 18.9 Simple support routines. 217 18.10 File name completion. 217 19.1 Tag configurations for basic character styles. 224 19.2 Line spacing and justification in the text widget. 225 19.3 An active text button. 228 19.4 Delayed creation of embedded widgets. 229 20.1 A large scrollable canvas. 236 20.2 The canvas "Hello, World!" example. 236 20.3 A min max scale canvas example. 238 20.4 Moving the markers for the min max scale. 240 20.5 Canvas arc items. 242 20.6 Canvas bitmap items. 243 20.7 Canvas image items. 244 20.8 A canvas stroke drawing example. 244 20.9 Canvas oval items. 246 20.10 Canvas polygon items. 247 20.11 Dragging out a box. 248 20.12 Simple edit bindings for canvas text items. 250 20.13 Using a canvas to scroll a set of widgets. 252 20.14 Generating postscript from a canvas. 257 21.1 Paste the PRIMARY or CLIPBOARD selection. 261 21.2 A selection handler for canvas widgets. 264 22.1 A read event file handler. 269 22.2 The sender application. 271 22.3 Using the sender application. 273 22.4 Hooking the browser to an eval server. 275 22.5 Making the shell into an eval server. 276 23.1 Equal-sized labels. 279 23.2 3D relief sampler. 280 23.3 Padding provided by labels and buttons. 282 23.4 Anchoring text in a label or button. 282 23.5 Borders and padding. 283 24.1 Resources for reverse video. 285 24.2 Computing a darker color. 287 24.3 Specifying an image for a widget. 289 24.4 Specifying a bitmap for a widget. 290 24.5 The built-in bitmaps. 291 24.6 The X cursor font. 294 25.1 FindFont matches an existing font. 299 25.2 Handling missing font errors. 299 25.3 FontWidget protects against font errors. 300 25.4 A gridded, resizable listbox. 301 25.5 A font selection application. 303 25.6 Using variable traces to fix things up. 304 25.7 Listing available fonts. 304 25.8 Determining possible font components. 305 25.9 Creating the radiobutton menu entries. 306 25.10 Setting up the label and message widgets. 306 25.11 The font selection procedures. 307 26.1 Gridded geometry for a canvas. 310 26.2 Telling other applications what your name is. 314 27.1 A user interface to widget bindings. 322 27.2 Bind_Display presents the bindings for a widget or class. 323 27.3 Related listboxes are configured to select items together. 324 27.4 Controlling a pair of listboxes with one scrollbar. 324 27.5 Drag-scrolling a pair of listboxes together. 325 27.6 An interface to define bindings. 325 27.7 Defining and saving bindings. 327 28.1 Preferences initialization. 330 28.2 Adding preference items. 331 28.3 Setting preference variables. 332 28.4 Using the preferences package. 332 28.5 A user interface to the preference items. 333 28.6 Interface objects for different preference types. 334 28.7 Displaying the help text for an item. 335 28.8 Saving preferences settings to a file. 336 28.9 Read settings from the preferences file. 337 28.10 Tracing a Tcl variable in a preference item. 338 29.1 A canonical Tcl main program and Tcl_AppInit. 341 29.2 The RandomCmd C command procedure. 343 29.3 Calling C command procedure directly. 345 29.4 A Makefile for a simple Tcl C program. 347 29.5 Using the Hash package. 351 30.1 A canonical Tk main program and Tcl_AppInit. 354 30.2 A custom Tk main program. 355 30.3 Using Tk_DoOneEvent with TK_DONT_WAIT. 359 31.1 The Clock widget data structure. 370 31.2 Configuration specs for the clock widget. 371 31.3 The ClockCmd command procedure. 373 31.4 The ClockInstanceCmd command procedure. 374 31.5 ClockConfigure allocates resources for the widget. 376 31.6 ComputeGeometry computes the widget's size. 378 31.7 The ClockDisplay procedure. 379 31.8 The ClockEventProc handles window events. 381 31.9 The ClockDestroy cleanup procedure. 382 32.1 A sample expect script. 392 32.2 A SIGINT handler. 395 32.3 Summary of [incr Tcl] commands. 401 32.4 Tcl_AppInit and extension packages. 403 32.5 Makefile for supertcl. 405