Version 4 of What kinds of variables can Tcl scripts use

Updated 2003-10-29 10:38:48

Purpose: discuss for the beginner the types of variables a user can use in a Tcl script.


  • [Discuss characters permitted in a variable name, format of a variable name, when to use the $ and when not, etc.]
  • Types of variables
  • In the core of Tcl
  • Scalar
  1. String - an arbitrary series of bytes. As far as I am aware, any byte value (from 0 length up to nearly the amount of available virtual memory remaining in your system) is considered a string.
  2. Character String - a special case of the previous type. Character strings are kept by Tcl in UTF-8. Most Tcl commands expect to work on character strings. If your string is not a character string (but instead is a series of bytes of binary data), you should be careful what functions you use.
  3. List - another special case of string. In this case, the string consists of a series of elements either joined together via list, or a character string split into elements. Once a list has been constructed, individual elements can be accessed via certain Tcl commands, such as lindex, designed to expect a list as input.
  4. Handle - a symbolic string which tcl translates internally via a table into typically a pointer. An example of a handle is the value returned by open. The value that is returned is not intended to be manipulated with expr, etc. Instead, the value is important only to functions which understand the particular kind of handle. There is no type info in the handle, so one can get broken behavior by indiscriminate passing of handles to routines expecting a different type of handle.
  5. Namespace - a specialized handle, used to [fill in the rest]
  6. Thread - a specialized handle, used to [fill in the rest] [Can you access this type of variable without the seperate Thread extension?]
  7. Regular Expression - REs can be pre-compiled by the call "regexp $RE {}" [L1 ].
  8. Interpreter - a specialized handle, used to [fill in the rest]

  • In common extensions
  • In Tk, the special variable types are specialized handles.
  1. widget - a handle representing a type of (usually visual) component for creating graphical interfaces. Some examples are frame, button, menu, text, entry, and so forth.
  2. font - this handle represents a combination of face, size, and thickness that can then be used when specifying to a widget how to display text
  3. image - this handle represents an image

  • In TclX
  1. keyed list - this specialized version of a list permits one to create pairs of key/value elements for the list and then retrieve values by specifying the key desired. It allows representing data a bit more structured. Keyed lists are intended to provide array like functionality but in a list format,

  • In BLT
  1. vector - specialized data type to handle large amounts of data rapidly
   [[Add other extensions which create new types of variables]]