Tcl and its extensions, Tk and Expect, are powerful tools that allow you greater control over your systems, and easier control of interactions between systems.
This the primary starting point for those looking to learn Tcl. Is there a topic you feel should be discussed but which often isn't? Add it to one of the categories below!
RS: A hint not only for beginners: due to its interactive nature, Tcl itself is a very good teacher. Start up an interactive tclsh (i.e. not specifying a script file). Type commands in, see how it reacts. Make intentional errors (you can hardly break anything). Read the error messages, they're very often very helpful.
LV: I would, however, suggest that they could locate and use tkcon, if tclsh's minimalistic interface is difficult to use. Also, if you are using vanilla tclsh, read up on the history command.
See Also
- Dodekalogue
- The rules of Tcl
- A User's Guide to Tcl/Tk
- Documentation
- Tcl Developer Guide
- The entry point for the practioner.
- Beginning Tk
- Learn to wield the most productive GUI toolkit ever.
- Learn to Program
- The general art of programming introduced from a Tcl perspective.
- Tcl Commands
- Manpage extracts for selected commands - and extra notes that are not in the manual.
- Advanced Tcl
- Topics which usually come up after someone has a grasp on the basics of Tcl and Tk.
Preliminaries
- Getting Started
- Starter Tcl
- Show me an example
- A step-by-step walkthrough of a first Tcl program.
- IDE
- Tcl Editors
- Why is keyboard entry in Tcl so crude?
- Is tclsh or wish suitable as a login shell?
Where to Ask for Help
It's always a good idea to search this wiki and the Internet for answers first. If good information is not to be found, the following resources provide information on where and how to ask for help. Also check out Effective ways to request help with Tcl-related problems.
- comp.lang.tcl
- One of the best places to ask for help. Make sure to read the introduction and posting style guide first.
- Tcl Questions and Answers
- Ask, and it shall be given.
John Ousterhout, the creator of Tcl, produced various tutorials, guides, and references, and also the classic book on Tcl.
- BOOK Tcl and the Tk Toolkit
- An Overview of Tcl and Tk
- An Introduction to Tcl Scripting
- Based on John's powerpoint tutorials.
- Writing Tcl-Based Applications in C
- Based on John's powerpoint tutorials.
- Building User Interfaces with Tcl and Tk
- Based on John's powerpoint tutorials.
- postscript versions of John's powerpoint tutorials
- Scripting: Higher Level Programming for the 21st Century
- IEEE Computer Magazine, 1998-03. The article that layed out Ousterhout's Dichotomy
Books
- Practical Programming in Tcl and Tk
- (in print)
- Effective Tcl - Writing Better Programs in Tcl and Tk
- Tcl and the Tk Toolkit
- Tcl/Tk How To Program . A Book In Arabic
Tutorials
- Online Tcl and Tk Tutorials
- discussion page
Beginner Introductions
- tcltutorial
- a community tutorial
- An Introduction to Tcl Scripting
- What is Tcl
- Tcl Intro
- Tcl for beginners
- Show me an example
- Talk to me, Tcl
- How to learn using an interactive Tcl.
- Unix Shells
- An introduction to Tcl syntax by comparision with Unix shell syntax.
Technical Introductions
- An Overview of Tcl and Tk
- An Introduction to Tcl Scripting
- Intermediate Tcl
- Resources at the intermediate level.
- Advanced Tcl
- Resources at the advanced level.
Curricula
- Tcl for Kids
- Tcl Learning Exercises
- A list of exercises, in order of difficulty.
- braintwister
- A guide to pages containing examples that give your Tcl I.Q. a workout.
- Who Wants to Be a Tcl Hacker: Quiz Game
- Customize the questions and answers to any subject and have some fun with your students.
Exercises
- HelloWorld
- Simple working examples to try one's hand at.
- What's My Line?
- A game-like exercise where the goal is to guess the output of the Tcl script.
- Programming Language Examples Alike Cookbook
- Reimplements in other languages, including Tcl, examples from the O'Reilly Perl Cookbook
Learning Programs
- TclRobots
- A programming game in which one writes Tcl programs to control a robot which must survive a battle with other robots.
- Tcl Tutor
- A free, downloadable, multi-platform tutorial for Tcl.
- Tcltalk
- An interactive learning tool and development environment for Tcl/Tk.
Key Concepts
The following list might be better suited for some other page, but until a better home is found, it lives here. This is a list of are concepts that have proven vital for a good working understanding of Tcl, and should help to get one's bearings if new to the language:
- The Dodekalogue is a fine thing
- A little time invested in digesting the dodekalogue has an enormous payoff.
- Every value is a string (EIAS)
- Every value in Tcl is a string, and each command decides on its own how to interpret the values it receives as arguments. Because every value is a string, Tcl and its extensions often expose external resources and data structures as handles, i.e., a string naming the resource. open, for example, returns a string that can be used as the handle for an open file.
- Double quotes are not a string contructor
- Every value already is a string. Double quotes, braces, and the backslash character merely escape the special meaning of various characters in Tcl syntax, indicating that whitespace, $, or [, ", {, or \ charactes are a part of the value rather than a special instruction to Tcl.
- Braces are not a list constructor
- Rather, a value is a list if it conforms to the prescribed format of a list, which uses braces and the backslash character as needed to distinguish between items in the list and the whitespace delimiting those items. One of the biggest misconceptions among Tcl script authors is that one can cobble together a list by adding values to a string and separating them with whitespace. The technique appears at first to work for a lot of values, but eventually some value that needs proper quoting turns up. Avoid problems by using list to create a properly-formatted list, and use commmands like lappend and lset to manipulate those lists.
- Brace your expressions
- If expr receives one literal string as an argument, its performance is often much better. Also, since expr does its own variable and command substituion, bracing the arguments to expr protects against the perils of double substitution.
- Prefer {*} over eval
- {*} is worth understanding from the get-go.
- Command substitution is actually script substitution
- An entire script, not just a single command, can go between the brackets. The value of the substitution is the value of the final command in the script.
- An array is a collection of variables, while a dict is a list mapping keys to values
- Both are fit for various purposes in a script, with some overlap. dict is not intended to replace array, but rather as another useful feature in its own right.
- Values are copy-on-write
- New Tcl programmers are tempted to do gymnastics in their scripts to avoid what they perceive as additional memory costs of passing values around. In fact, Tcl doesn't actually copy the value until modification of the value makes it necessary. the unshared value idiom can be used to avoid the making of a copy when a value is modified.
- a command that modifies a value takes as an argument the name of the variable holding the value
- This is an example of using a string as a handle, and is the natural way to design a function whose purpose is to modify some value named by the caller. In contrast, commands that simply use the value without modifying it take as an argument the actual value rather than th name of variable holding the value. This pattern is evident throughout the built-in commands.
- Commands often implement domain-specific languages
- expr and regexp are examples of this. Tcl was designed as a language for creating domain-specific languages, and this idea permeates Tcl scripts and extensions. Many DSL's share the syntax of Tcl.
- The event loop that is built into Tcl is quite handy
- It's a more advanced topic, and usually requires a program to be structured quite differently, but a built-in event loop is one of those things that differentiates Tcl from other scripting languages. It is a good idea to learn to take full advantage of the event loop before turning to threads. Those using Tk will find it necessary to get familiar with the event loop in short order.
Tips and Tricks
Important advice, heard from RS: "Tcl is so good in introspection, that you should always have an interactive tclsh around for testing - way faster than c.l.t, and more convenient than reading the man pages, or thinking oneself ;-)"
Stages of Progression
Documentation
C API
- Writing Tcl-Based Applications in C
Instructional Pages, Beginner
This is a selection of pages deemd to be particularly intructive for learning Tcl idioms and usage. The Tk page has a similar section specifically for Tk usage
- Arrays / hash maps
- Tcl Quoting
- Slurping Up Text in Tcl
- Tcl Gems
- Bag of Algorithms
- useful code examples
- Sample Math Programs
- really simple examples of using programming to solve math problems
- Braintwisters
- a little learning decision tree
- A simple but engaging lesson in creating a program that learns.
- The infinity trick
- working with "infinity" in expressions
- Tcl examples
- more Tcl examples
- Regular expressions
- Uwe Klein
- a bunch of fairly simple Tcl and Tk examples
- Additional math functions
- Sample math programs
- very simple examples if you have some math background
- How to make a Tcl application
- What kinds of variables can Tcl scripts use?
- What kinds of variable names can be used in Tcl?
- Tcl variable scope - how does Tcl control when a variable is seen?
- What kinds of data can Tcl scripts use?
- Is white space significant in Tcl?
- Why can I not place unmatched braces in Tcl comments?
- How can I do math in Tcl?
- How am I supposed to handle errors in Tcl?
- What debugging tools are available to a Tcl programmer?
- How do I read and write files in Tcl?
- How can I get input from a user and then safely make use of it?
- How would I program 'ring around a rosie' - looping constructs?
- How would I reuse my own Tcl code?
- Are there any recommendations or requirements regarding what order code appears in a Tcl program?
- Concepts of Architectural Design for Tcl Applications
- Setting /bin/sh environment variables in the script
- Tcl/Tk Engineering Manual
- by John Ousterhout, engineering style guidelines for coding Tcl code
- Tcl and octal numbers
- How to deal with the fact that in numeric contexts, Tcl interprets values such as 042 as octal numbers.
- What some command arguments expect
- A tutorial regarding double substitution.
Instructional Pages, Intermediate
- Keith Vetter
- A large number of very interesting but small programs
- Syntax parsing in Tcl
- Braintwisters
- A simple database
- Complex data structures
Resources
- Contents
- contents of this wiki
- Demo
- Pointers to fun and educational tcl demos.
- Frequently-Made Mistakes in Tcl
- by CL
- Tcl Editors
- how to edit the text of a program
- Tcl Tutor
- Tcl Help
-
- gotcha
- a variety of illustrative code snippets
- Informal Tcl Book Reviews
- TCL programs for beginners 1-10
- Tcl cheat sheet
-
- Glossary of terms
- Acronym collection
- Tcl-URL!
- Practice Scripts
- A list of scripts people have written to learn Tcl
- Richard Suchenwirth
- a rich variety of Tcl examples dealing with Unicode, dates, graphics, and more
- Donal Fellows
- Arts and Crafts of Tcl-Tk programming
- Dirty Dozen
- a selection of web resources related to Tcl
- Example scripts everybody should have
- Tcl Articles
- a list of articles about Tcl
- Teaching Tcl
- a discussion about teaching Tcl (not really for those learning Tcl)
- Common questions about Tcl
- Simple Tcl Code << 3D Egg - glx docs
- short and simple learning examples of oo, socket, and coroutine
- Expect Exceeds Expectations, Cameron Laird, 2002
- Argues that Expect is the one language you most need to learn
Training
- IT-Schulungen.com (German)
- Lynda.com's Tcl/TK Training and Tutorials page
- Alas, it consists of a course on Tkinter.
Misc
- license
Historical
- Tcl/Tk Quick Reference Guide for 8.0
- Tcl/Tk Quick Reference Guide, updated fo 8.4, by Bob Bodenstab
What Links Here
Fetching backrefs...