Contents

    Preface

I  Tcl: The Tool Command Language

    1  Getting Started
        1.1  Running Tcl
        1.2  Hello World!
        1.3  Variables and Values
        1.4  Evaluation and Substitution
            1.4.1  Backslash Substitution
        1.5  Arithmetic
            1.5.1  Operands
                1.5.1.1  Big Integers
            1.5.2  Operators
                1.5.2.1  Logical and Relational Operators
                1.5.2.2  Arithmetic Operators
                1.5.2.3  Bitwise Operators
                1.5.2.4  String and List Operators
            1.5.3  Math Functions
            1.5.4  Incrementing Integers

    2  Handling Data
        2.1  Strings
            2.1.1  Unicode
            2.1.2  Pattern Matching
        2.2  Dates and Times
        2.3  Lists
            2.3.1  List Variable Commands
            2.3.2  Nested Lists
            2.3.3  Sorting and Searching
        2.4  Dictionaries
            2.4.1  Filtering a Dictionary
            2.4.2  Updating a Dictionary
        2.5  Arrays
        2.6  Regular Expressions
            2.6.1  Crafting Regular Expressions

    3  Control Structures
        3.1  Branching with if and switch
            3.1.1  The if Command
            3.1.2  The switch Command
        3.2  Loops: while and for
            3.2.1  The while Loop
            3.2.2  The for Loop
            3.2.3  Early termination: break and continue
            3.2.4  The foreach Loop
        3.3  Procedures
            3.3.1  Parameters and Arguments
            3.3.2  Global and Local Variables
            3.3.3  The return Command
            3.3.4  The Procedure Call Stack
            3.3.5  Recursion: Looping without loops!
            3.3.6  Higher-Order Procedures and Callbacks
            3.3.7  Anonymous Procedures
            3.3.8  Command Aliases
            3.3.9  Examining Procedures
        3.4  Dealing with Errors
            3.4.1  The try Command
                3.4.1.1  Error Options Dictionary
                3.4.1.2  The finally Clause
                3.4.1.3  Other Exceptions
            3.4.2  The catch Command
            3.4.3  Throwing Errors and Exceptions
                3.4.3.1  The throw Command
                3.4.3.2  The error Command
                3.4.3.3  Throwing Other Exceptions

    4  Program Organisation
        4.1  Namespaces
            4.1.1  Ensembles
            4.1.2  Import and Export
            4.1.3  Creative Writing
            4.1.4  Paths and Unknown Commands
            4.1.5  Abstract Data Types
                4.1.5.1  Example: Stacks and Queues
                4.1.5.2  Example: Algebraic Types
        4.2  Packages
            4.2.1  Modules
        4.3  Object Oriented Tcl
        4.4  Testing
            4.4.1  TclTest

    5  Input and Output
        5.1  Command Line Arguments and Environment Variables
        5.2  Channels
        5.3  The File System
        5.4  Processes
        5.5  TCP/IP Networking

    6  The Event Loop
        6.1  Introduction
        6.2  Delayed Tasks
        6.3  Channel Events
        6.4  Variable and Command Traces

    7  Advanced Topics
        7.1  Custom Control Structures
        7.2  Unknown Command Handlers
        7.3  Coroutines
        7.4  Interpreters
        7.5  Threads

II  Tk: Graphical User Interfaces

    8  Basic Concepts
        8.1  Introduction

    9  Managing toplevel windows

    10  Basic Widgets
        10.1  Labels
        10.2  Entry widgets
            10.2.1  Validation
        10.3  Buttons
        10.4  Checkbuttons
        10.5  Radio buttons
        10.6  Scales
        10.7  Scrollbars
        10.8  Spinboxes
        10.9  Comboboxes
        10.10  Progressbars
        10.11  Separators

    11  Geometry Management
        11.1  Placing the widgets

    12  The Text Widget
        12.1  Positions in the text
        12.2  Tags
        12.3  Searching
        12.4  Hypertext
        12.5  Formatted text
        12.6  More information

    13  The Canvas Widget

    14  Themed Tk

III  Real-World Application Development

    15  Tcl Database Connectivity (TDBC)

    16  XML

    17  Web Applications and Services
                17  References