Home
Programming
AspectJ   Basic   C   C++   C#   Eiffel   Java   JavaScript   Pascal   PHP   Python   Rexx   Ruby   Scriptol   Tcl
Markup
HTML   XML   XAML   XUL
Query
SQL

TCL - Portable Scripting and CGI

Tcl, Tool Command Language (pronounce tickle) was created by John Ousterhout in 1988. The graphical toolkit Tk has been available in 1991.
This is an interpreted scripting language, easy to learn where each thing is a command and can be redefined. The syntax uses plenty of symbols as C but is not that of C. (In C each thing is an expression).

Features

Syntax

An instruction is the name of a command (not a keyword) followed by a list of words separated by a whitespace, the arguments.
Statements end with the end of the line. They may be separated by a semi-colon on a same line.
Square brackets replace an argument by a command. These are so a substitution  symbols.
The = sign is never used, the "set" command assigns a value to a variable:

set varname value

The { } serve for grouping, without subsitution.
# introduces a comment.

Control structures

The if command use two groups { }, the first for the condition, the second for the actions.

if { x < 10 } 
{
puts "x less than 10"
}

The while command has the same syntax.

Procedures

The definition starts with the proc command, plus the name and two groups for the arguments and the statements.

proc procname { arguments }
{
...statements...
}

Why to use Tcl?

The language is used for scripting and prototyping. It may be a replacement for Perl, as CGI for web services. The language and the graphical toolkit are ported on almost all operating systems and they may be used for the advantage of portability.

Sites

Sample code

Hello world!
puts "Hello, world!" 
Content of an array
array mylist { d e m o } 

foreach i [ array mylist ]
{
  puts [ concat $i = $mylist($i) ]
}

References

Home