All Topics  
Tcl

 

   Email Print
   Bookmark   Link






 

Tcl



 
 
Tcl (originally from "Tool Command Language", but nonetheless conventionally rendered as "Tcl" rather than "TCL"; pronounced as "tickle" or "tee-cee-ell") is a scripting language
Scripting language

A scripting language, script language or extension language, is a programming language that allows some control of a single or many Application software....
 created by John Ousterhout
John Ousterhout

John Kenneth Ousterhout is the chairman of Electric Cloud and a professor of computer science at Stanford University. He founded Electric Cloud with John Graham-Cumming....
. Originally "born out of frustration"—according to the author—with programmers devising their own (poor quality) languages intended to be embedded into applications, Tcl quickly gained wide acceptance on its own and is generally thought to be easy to learn, but powerful in competent hands.






Discussion
Ask a question about 'Tcl'
Start a new discussion about 'Tcl'
Answer questions from other users
Full Discussion Forum



Encyclopedia


Tcl (originally from "Tool Command Language", but nonetheless conventionally rendered as "Tcl" rather than "TCL"; pronounced as "tickle" or "tee-cee-ell") is a scripting language
Scripting language

A scripting language, script language or extension language, is a programming language that allows some control of a single or many Application software....
 created by John Ousterhout
John Ousterhout

John Kenneth Ousterhout is the chairman of Electric Cloud and a professor of computer science at Stanford University. He founded Electric Cloud with John Graham-Cumming....
. Originally "born out of frustration"—according to the author—with programmers devising their own (poor quality) languages intended to be embedded into applications, Tcl quickly gained wide acceptance on its own and is generally thought to be easy to learn, but powerful in competent hands. It is most commonly used for rapid prototyping
Rapid prototyping

Rapid prototyping is the automatic construction of physical objects using solid freeform fabrication. The first techniques for rapid prototyping became available in the late 1980s and were used to produce models and prototype parts....
, scripted applications, GUIs and testing. Tcl is used extensively on embedded systems platforms, both in its full form and in several other small-footprinted versions. Tcl is also used for CGI
Common Gateway Interface

The Common Gateway Interface is a Standardization Protocol for interfacing external application software with an Server , commonly a web server....
 scripting and as the scripting language for the Eggdrop
Eggdrop

Eggdrop is a popular IRC bot and is the oldest IRC bot still in active Software development....
 bot.

The combination of Tcl and the Tk
Tk (framework)

Tk is an open source, cross-platform widget toolkit, that is, a library of basic elements for building a graphical user interface .Tk provides a number of widgets commonly needed to develop desktop applications such as button, menu, canvas, text, frame, label etc....
 GUI toolkit
Widget toolkit

A widget toolkit, widget library, or GUI toolkit is a set of GUI widget for use in designing applications with graphical user interfaces ....
 is referred to as Tcl/Tk.

History

The Tcl programming language was created in the spring of 1988 by John Ousterhout
John Ousterhout

John Kenneth Ousterhout is the chairman of Electric Cloud and a professor of computer science at Stanford University. He founded Electric Cloud with John Graham-Cumming....
 while working at the University of California, Berkeley
University of California, Berkeley

The University of California, Berkeley is a public university research university located in Berkeley, California, California, United States. The oldest of the ten major campuses affiliated with the University of California, Berkeley offers some 300 undergraduate and graduate degree programs in a wide range of disciplines....
.

Date Event
January 1990 Tcl announced beyond Berkeley (Winter USENIX
USENIX

The USENIX Association is the Advanced Computing Technical Association. It was founded in 1975 under the name "Unix Users Group," focusing primarily on the study and development of Unix and similar systems....
).
June 1990 Expect
Expect

Expect is a Unix automation and testing tool, written by Don Libes as an extension to the Tcl scripting language, for interactive application software such as telnet, ftp, Passwd , fsck, rlogin, tip , Secure Shell, and others....
 announced (Summer USENIX).
January 1991 First announcement of Tk
Tk (framework)

Tk is an open source, cross-platform widget toolkit, that is, a library of basic elements for building a graphical user interface .Tk provides a number of widgets commonly needed to develop desktop applications such as button, menu, canvas, text, frame, label etc....
 (Winter USENIX).
June 1993 First Tcl/Tk conference (Berkeley). [table] geometry manager (forerunner of [grid]), [incr Tcl], TclDP and Groupkit, announced there.
September 2002 Ninth Tcl/Tk conference (Vancouver). Announcement of starkit packaging system.


Tcl conferences and workshops are held in both the United States and Europe.

Features

Tcl's features include

  • Everything is a command
    Command (computing)

    In computing, a command is a directive to a computer program acting as an interpreter of some kind, in order to perform a specific task. Most commonly a command is a directive to some kind of command line interface, such as a shell ....
    , including language structures. They are in Prefix notation.
  • Commands can be variadic
    Variadic

    In computer science, a variadic operator or function is one that can take a varying number of argument s; that is, its arity is not fixed.For specific articles, see:...
    .
  • Everything can be dynamically redefined and overridden.
  • All data type
    Data type

    A data type in programming languages is an attribute of a data which tells the computer something about the kind of data it is. This involves setting constraints on the datum, such as what values it can take and what operations may be performed upon it....
    s can be manipulated as strings
    String (computer science)

    In computer programming and some branches of mathematics, a string is an ordered sequence of symbols. These symbols are chosen from a predetermined set or alphabet....
    , including code
    Code

    In communications, a code is a Operator for converting a piece of information into another form or representation , not necessarily of the same type....
    .
  • Extremely simple syntactic
    Syntax of programming languages

    In computer science, the syntax of a programming language is the set of rules that define the combinations of symbols that are considered to be syntactically correct computer programs in that language....
     rules.
  • Event-driven interface
    Event-driven programming

    In computer programming, event-driven programming or event-based programming is a programming paradigm in which the Program flow is determined by event s — i.e., sensor outputs or user actions or Message passing from other programs or Thread_....
     to socket
    Socket

    Socket can refer to:In mechanics:* Socket wrench, a type of wrench that uses separate, removable sockets to fit different sizes of nuts and bolts...
    s and file
    Computer file

    A computer file is a block of arbitrary information, or resource for storing information, which is available to a computer program and is usually based on some kind of durable computer storage....
    s. Time-based and user-defined events are also possible.
  • Flexible scope
    Scope (programming)

    In computer programming, scope is an enclosing context where values and expressions are associated. Various programming languages have various types of scopes....
    , with variable visibility restricted to lexical (static) scope by default, but uplevel
    Uplevel

    Uplevel is a command in Tcl that allows a command script to be executed in a scope other than the current innermost scope on the stack. Because the command script may itself call procedures that use the uplevel command, this has the net effect of transforming the call stack into a call tree....
     and upvar allowing procs to interact with the enclosing functions' scopes.
  • Simple exception handling using exception code returned by all command executions.
  • All commands defined by Tcl itself generate informative error messages on incorrect usage.
  • Readily extensible
    Extensibility

    In software engineering, extensibility is a system design principle where the implementation takes into consideration future growth. It is a systemic measure of the ability to extend a system and the level of effort required to implement the extension....
    , via C
    C (programming language)

    C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system....
    , C++
    C++

    C++ is a general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level programming language and low-level programming language language features....
    , Java
    Java (programming language)

    Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java ....
    , and Tcl.
  • Interpreted language
    Interpreted language

    In computer programming an interpreted language is a programming language whose implementation often takes the form of an interpreter . Theoretically, any language may be compiler or interpreted, so this designation is applied purely because of common implementation practice and not some underlying property of a language....
     using bytecode
    Bytecode

    Bytecode is a term which has been used to denote various forms of instruction sets designed for efficient execution by a software Interpreter as well as being suitable for further compilation into machine language....
     for improved speed whilst maintaining dynamic modifiability
  • Full Unicode
    Unicode

    Unicode is a computing industry standard allowing computers to consistently represent and manipulate Character expressed in most of the world's writing systems....
     (3.1) support, first released 1999.
  • Platform independent: Win32, UNIX
    Unix

    Unix is a computer operating system originally developed in 1969 by a group of American Telephone & Telegraph employees at Bell Labs, including Ken Thompson , Dennis Ritchie, Douglas McIlroy, and Joe Ossanna....
    , Linux
    Linux

    Linux is a generic term referring to Unix-like computer operating systems based on the Linux kernel. Their development is one of the most prominent examples of free and open source software collaboration; typically all the underlying source code can be used, freely modified, and redistributed by anyone under the terms of the GNU GPL license...
    , Mac, etc.
  • Close integration with windowing (GUI
    Gui

    Gui or guee is a generic term to refer to grillinged dishes in Korean cuisine. These most commonly have meat or fish as their primary ingredient, but may in some cases also comprise grilled vegetables or other vegetarian ingredients....
    ) interface Tk
    Tk (framework)

    Tk is an open source, cross-platform widget toolkit, that is, a library of basic elements for building a graphical user interface .Tk provides a number of widgets commonly needed to develop desktop applications such as button, menu, canvas, text, frame, label etc....
    .
  • Can be used for many purposes, and in many environments: as a text-only scripted language, as a GUI-capable language for applications, as an embedded language in: web pages (server-side), and databases (server-side, in PostgreSQL
    PostgreSQL

    PostgreSQL is an object-relational database management system . It is released under a BSD licenses and is thus free software. As with many other open-source programs, PostgreSQL is not controlled by any single company, but has a global community of developers and companies to develop it....
    ).
  • Exists as development version (e. g. ActiveState Tcl), as tclkit (kind of runtime version, only about 1 megabyte in size), as starpack (single-file executable of a script/program), as BSD licensed freely distributable source


Tcl did not originally support object oriented
Object-oriented programming

Object-oriented programming is a programming paradigm that uses "Object_" and their interactions to design applications and computer programs....
 syntax before 8.6 (8.6 provides a OO system in Tcl core), but recent versions do support extensions which provide OO functionality, such as the XOTcl
XOTcl

XOTcl is an object-oriented extension for the Tcl created by G. Neumann and U. Zdun. It supports metaclasses. Class and Method definitions are completely dynamic....
 extension to Tcl. Other OO extensions also exist, such as incr Tcl, Snit
Snit

Snit is an object-oriented extension to the Tcl programming language. Snit is a recursive acronym that stands for "Snit's Not Incr Tcl." Snit is a pure Tcl Object and megawidget system....
, and STOOOP (simple tcl-only object-oriented programming).

Syntax and Fundamental Semantics

A Tcl script consists of several command invocations. A command invocation is a list of words separated by whitespace and terminated by a newline or semicolon.

word0 word1 word2 ... wordN

The first word is the name of a command, which is not built into the language, but which is in the library. The following words are arguments. So we have:

commandName argument1 argument2 ... argumentN

Practical example, using the puts command which outputs a string, adding a trailing newline, by default to the stdout channel:

puts "Hello, world!"

Variables and the results of other commands can be substituted inside strings too, such as in this example where we use set and expr to store a calculation result in a variable, and puts to print the result together with some explanatory text:

set sum [expr 1+2+3+4+5] puts "The sum of the numbers 1..5 is $sum."

Formally, words are either written as-is, with double-quotes around them (allowing whitespace characters to be embedded), or with curly-brace characters around them, which suppresses all substitutions inside (except for backslash-newline elimination). In bare and double-quoted words, three types of substitution occur (once, in a single left-to-right scan through the word):
  • Command substitution replaces the contents of balanced square brackets with the result of evaluating the script contained inside. For example, “[expr 1+2+3]” is replaced with the result of evaluating the contained expression (i.e. 6) since that's what the expr command does.
  • Variable substitution replaces a dollar-sign followed by the name of a variable with the contents of the variable. For example, “$foo” is replaced with the contents of the variable called “foo”. The variable name may be surrounded in curly braces so as to delimit what is and isn't the variable name in otherwise ambiguous cases.
  • Backslash substitution replaces a backslash followed by a letter with another character. For example, “\n” is replaced with a newline.
From Tcl 8.5 onwards, any word may be prefixed by “” to cause that word to be split apart into its constituent sub-words for the purposes of building the command invocation (similar to the “,@” sequence of Lisp's quasiquote feature).

As a consequence of these rules, the result of any command may be used as an argument to any other command. Also, there is no operator or command for string concatenation, as the language concatenates directly. Note that, unlike in Unix command shells
Bourne shell

The Bourne shell, or sh, was the default Unix shell of Version 7 Unix, and replaced the Thompson shell, whose executable file had the same name, sh....
, Tcl does not reparse any string unless explicitly directed to do so, which makes interactive use more cumbersome but scripted use more predictable (e.g. the presence of spaces in filenames does not cause difficulties).

To summarize: there is one basic construct (the command) and a set of simple substitution rules. The single equality sign (=) for example is not used at all, and the double equality sign (

) is the test for equality, and even then only in expression contexts such as the expr command or the first argument to if. (Both of those commands are just part of the standard library; they have no particularly special place in the library and can be replaced if so desired.)

The majority of Tcl commands, especially in the standard library, are variadic
Variadic function

In computer programming, a variadic function is a function of variable arity; that is, one which can take different numbers of arguments. Support for variadic functions differs widely among programming languages....
, and the proc (the constructor for scripted command procedures) supports the definition of both default values for arguments and a catch-all argument to allow the code to process arbitrary numbers of arguments.

Tcl is not statically typed: each variable may contain integers, floats, strings, lists, command names, dictionaries, or any other value; values are reinterpreted (subject to syntactic constraints) as other types on demand. However, values are immutable
Immutable object

In object-oriented computer programming and Functional_programming programming, an immutable object is an object whose state cannot be modified after it is created....
 and operations that appear to change them actually just return a new value instead.

Interfacing with other languages

Tcl interfaces natively with the C
C (programming language)

C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system....
 language. This is because it was originally written to be a framework for providing a syntactic front-end to commands written in C, and all commands in the language (including things that might otherwise be keyword
Keyword (computer programming)

In computer programming, a keyword is a word or identifier that has a particular meaning to the programming language. The meaning of keywords ? and, indeed, the meaning of the notion of keyword ? differs widely from language to language....
s, such as if or while) are implemented this way. Each command implementation function
Subroutine

In computer science, a subroutine or subprogram is a portion of computer code within a larger computer program, which performs a specific task and is relatively independent of the remaining code....
 is passed an array of values that describe the (already substituted) arguments to the command, and is free to interpret those values as it sees fit.

Digital logic simulators
Logic simulation

Logic simulation is the use of a computer program to simulate the operation of a digital circuit. Logic simulation is the primary tool used for verifying the logical correctness of a hardware design....
 often include a Tcl scripting interface for simulating Verilog
Verilog

In the semiconductor and electronic design industry, Verilog is a hardware description language used to model Electronics#Electronic systems. Verilog HDL, not to be confused with VHDL, is most commonly used in the design, verification, and implementation of Digital circuit logic chips at the Register transfer level level of Abstraction...
, VHDL and SystemVerilog hardware languages
Hardware description language

In electronics, a hardware description language or HDL is any language from a class of computer languages and/or programming languages for formal description of digital logic and electronic circuits....
.

Tools exist (e.g. SWIG
SWIG

SWIG is an open source software tool used to connect computer program or library written in C /C++ with scripting languages such as Tcl, Perl, Python , Ruby programming language, PHP, Lua , R_language and other languages like Java , C Sharp programming language, Scheme and Ocaml....
, ) to automatically generate the necessary code to connect arbitrary C functions and the Tcl runtime, and does the reverse, allowing embedding of arbitrary C code inside a Tcl script and compiling it at runtime into a DLL
Dynamic-link library

Dynamic-link library , or DLL, is Microsoft's implementation of the shared library concept in the Microsoft Windows and OS/2 operating systems....
.

C++ Interoperability


Java Interoperability


Extension packages

The Tcl language has always supported extension packages, which provide additional functionality (such as a GUI, terminal-based application automation, database access, etc.)

Tk

The most popular Tcl extension is the Tk
Tk (framework)

Tk is an open source, cross-platform widget toolkit, that is, a library of basic elements for building a graphical user interface .Tk provides a number of widgets commonly needed to develop desktop applications such as button, menu, canvas, text, frame, label etc....
 toolkit, which provides a graphical user interface
Graphical user interface

A graphical user interface is a type of user interface which allows people to human-computer interaction such as computers; hand-held devices such as MP3 Players, Portable Media Players or Gaming devices; household appliances and office equipment....
 library for a variety of operating system
Operating system

An operating system is an interface between hardware and applications; it is responsible for the management and coordination of activities and the sharing of the limited resources of the computer....
s. Each GUI consists of one or more frames. Each frame has a layout manager.

Tile/Ttk

Tile/Ttk is a styles and theming widget collection which can replace most of the widgets in Tk with variants which are truly platform native through calls to an operating system
Operating system

An operating system is an interface between hardware and applications; it is responsible for the management and coordination of activities and the sharing of the limited resources of the computer....
's API. Themes covered in this way are Windows XP
Windows XP

Windows XP is a line of operating systems produced by Microsoft for use on personal computers, including home and business desktops, laptop, and media centers....
, Windows Classic, Qt
Qt (toolkit)

Qt is a cross-platform application development framework, widely used for the development of graphical user interface programs , and also used for developing non-GUI programs such as console tools and servers....
 (which hooks into the X11 KDE
KDE

KDE is a free software project based around its flagship product, a desktop environment for Unix-like systems. The goal of the project is to provide basic desktop functions and applications for daily needs as well as tools and documentation for developers to write stand-alone applications for the system....
 environment libraries) and Aqua
Aqua (user interface)

Aqua is the graphical user interface and primary Theme of Apple Inc.'s Mac OS X operating system. It is based around the theme of water, as its name suggests, with droplet-like elements and liberal use of translucency and reflection effects....
 (Mac OS X). A theme can also be constructed without these calls using widget definitions supplemented with image pixmaps. Themes created this way include Classic Tk, Step, Alt/Revitalized, Plastik and Keramik.

Under Tcl 8.4, this package is known as Tile, while in Tcl 8.5 it is included in the core distribution as Ttk.

Itcl/IncrTcl

Itcl
Itcl

incr Tcl is a set of object-oriented extensions for the Tcl programming language. It is widely used among the Tcl community, and is generally regarded as industrial strength ....
 is an object system for Tcl, and is normally named as [incr Tcl] (that being the way to increment in Tcl, similar in fashion to the name C++).

Tcllib

Tcllib
Tcllib

Tcllib is a collection of packages available for the Tcl programming language. Tcllib is distributed in both source code as well as executable file formats....
 is a set of scripted packages for Tcl that can be used with no compilation steps.

Databases

Tcl Database Connectivity (TDBC) is accepted in v8.6. It is a common database access interface for Tcl scripts.

A number of database extensions are available:
  • tclodbc
  • mk4tcl
  • SQLite
    SQLite

    SQLite is an ACID-compliant relational database management system contained in a relatively small C programming library .Unlike client-server database management systems, the SQLite engine is not a standalone process with which the program communicates....
  • Pgtcl, pgintcl
  • mysqltcl, msqltcl
  • AdabasTcl
  • FBSQL
  • ibtcl
  • Oratcl
  • Sybtcl
  • db2tcl


See also

  • Eggdrop
    Eggdrop

    Eggdrop is a popular IRC bot and is the oldest IRC bot still in active Software development....
  • Expect
    Expect

    Expect is a Unix automation and testing tool, written by Don Libes as an extension to the Tcl scripting language, for interactive application software such as telnet, ftp, Passwd , fsck, rlogin, tip , Secure Shell, and others....
  • Itcl
    Itcl

    incr Tcl is a set of object-oriented extensions for the Tcl programming language. It is widely used among the Tcl community, and is generally regarded as industrial strength ....
  • Itk
    ITK

    ITK may stand for:* Inuit Tapiriit Kanatami, a Canadian organisation representing Inuit* Insight Segmentation and Registration Toolkit, an open source image Segmentation and Image registration software Library ...
  • Snit
    Snit

    Snit is an object-oriented extension to the Tcl programming language. Snit is a recursive acronym that stands for "Snit's Not Incr Tcl." Snit is a pure Tcl Object and megawidget system....
  • Tcllib
    Tcllib

    Tcllib is a collection of packages available for the Tcl programming language. Tcllib is distributed in both source code as well as executable file formats....
  • TclX
    TclX

    TclX extends the Tcl programming language by providing new operating system interface commands, extended file control, scanning and status commands and many others....
  • Tk
    Tk (framework)

    Tk is an open source, cross-platform widget toolkit, that is, a library of basic elements for building a graphical user interface .Tk provides a number of widgets commonly needed to develop desktop applications such as button, menu, canvas, text, frame, label etc....
  • XOTcl
    XOTcl

    XOTcl is an object-oriented extension for the Tcl created by G. Neumann and U. Zdun. It supports metaclasses. Class and Method definitions are completely dynamic....


External links



  • : Tcl and Tk website