Tcl
From Wikipedia, the free encyclopedia
This article includes a list of references or external links, but its sources remain unclear because it lacks inline citations. Please improve this article by introducing more precise citations where appropriate. (February 2008) |
This article is written like an advertisement. Please help rewrite this article from a neutral point of view. For blatant advertising that would require a fundamental rewrite to become encyclopedic, use {{db-spam}} to mark for speedy deletion. (September 2008) |
Paradigm | multi-paradigm: object-oriented, functional, procedural, event-driven programming |
---|---|
Appeared in | 1988 |
Designed by | John Ousterhout |
Developer | John Ousterhout |
Latest release | 8.5.6/ 2008-12-23 |
Typing discipline | dynamic typing, everything can be treated as a string |
Major implementations | ActiveTcl |
Influenced | PowerShell[1] |
Website | http://www.tcl.tk |
Tcl (originally from "Tool Command Language", but nonetheless conventionally rendered as "Tcl" rather than "TCL"; pronounced as "tickle" or "tee-cee-ell"[2]) is a scripting language created by John Ousterhout. Originally "born out of frustration"[3]—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[4], but powerful in competent hands. It is most commonly used for rapid prototyping, 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 scripting and as the scripting language for the Eggdrop bot.
The combination of Tcl and the Tk GUI toolkit is referred to as Tcl/Tk.
Contents |
[edit] History
The Tcl programming language was created in the spring of 1988 by John Ousterhout while working at the University of California, Berkeley.
Date | Event |
---|---|
January 1990 | Tcl announced beyond Berkeley (Winter USENIX). |
June 1990 | Expect announced (Summer USENIX). |
January 1991 | First announcement of Tk (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.
[edit] Features
Tcl's features include
- Everything is a command, including language structures. They are in Prefix notation.
- Commands can be variadic.
- Everything can be dynamically redefined and overridden.
- All data types can be manipulated as strings, including code.
- Extremely simple syntactic rules.
- Event-driven interface to sockets and files. Time-based and user-defined events are also possible.
- Flexible scope, with variable visibility restricted to lexical (static) scope by default, but uplevel 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, via C, C++, Java, and Tcl.
- Interpreted language using bytecode for improved speed whilst maintaining dynamic modifiability
- Full Unicode (3.1) support, first released 1999.
- Platform independent: Win32, UNIX, Linux, Mac, etc.
- Close integration with windowing (GUI) interface Tk.
- 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).
- 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 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 extension to Tcl. Other OO extensions also exist, such as incr Tcl, Snit, and STOOOP (simple tcl-only object-oriented programming).
[edit] 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:
# Good style would put the expression inside {curly braces} 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, 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, 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 and operations that appear to change them actually just return a new value instead.
[edit] Interfacing with other languages
Please help improve this section by expanding it. Further information might be found on the talk page. (January 2008) |
Tcl interfaces natively with the C 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 keywords, such as if or while) are implemented this way. Each command implementation function 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 often include a Tcl scripting interface for simulating Verilog, VHDL and SystemVerilog hardware languages.
Tools exist (e.g. SWIG, ffidl) to automatically generate the necessary code to connect arbitrary C functions and the Tcl runtime, and Critcl does the reverse, allowing embedding of arbitrary C code inside a Tcl script and compiling it at runtime into a DLL.
[edit] C++ Interoperability
[edit] Java Interoperability
[edit] 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.)
[edit] Tk
The most popular Tcl extension is the Tk toolkit, which provides a graphical user interface library for a variety of operating systems. Each GUI consists of one or more frames. Each frame has a layout manager.
[edit] 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's API. Themes covered in this way are Windows XP, Windows Classic, Qt (which hooks into the X11 KDE environment libraries) and Aqua (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 has been folded into the core distribution of Tk (as Ttk).
[edit] Itcl/IncrTcl
Itcl 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++).
[edit] Tcllib
Tcllib is a set of scripted packages for Tcl that can be used with no compilation steps.
[edit] Databases
Tcl Database Connectivity (TDBC), part of Tcl 8.6, is a common database access interface for Tcl scripts. It currently supports drivers for accessing MySQL, ODBC, and SQLite databases. More are planned for the future.
Access to databases is also supported through database-specific extensions, of which there are many available.
|
|
|
[edit] See also
Wikibooks has a book on the topic of |
[edit] References
- John K. Ousterhout, Tcl and the Tk Toolkit, Addison-Wesley, Reading, MA, USA, ISBN 0-201-63337-X, 1994.
- Brent B. Welch, Practical Programming in Tcl and Tk, Prentice Hall, Upper Saddle River, NJ, USA, ISBN 0-13-038560-3, 2003.
- J Adrian Zimmer, Tcl/Tk for Programmers, IEEE Computer Society, distributed by John Wiley and Sons, ISBN 0-8186-8515-8, 1998.
- Mark Harrison and Michael McLennan, Effective Tcl/Tk Programming, Addison-Wesley, Reading, MA, USA, ISBN 0-201-63474-0, 1998
- Mark Harrison (ed), Tcl/Tk Tools, O'Reilly Media, ISBN 1-56592-218-2, 1997
[edit] Notes
- ^ Windows PowerShell : PowerShell and WPF: WTF
- ^ From the Tcler's Wiki Tcl vs. TCL
- ^ From the inside flap of Tcl and the Tk Toolkit, ISBN 0-201-63337-X
- ^ Flynt, Clif. "Tcl/Tk - A developer's guide" (First edition ed.). Morgan Kaufmann Publishers. pp. 759. ISBN 1-55860-802-8.
[edit] External links
- Tcl-Tk at the Open Directory Project
- Tcl Developer Xchange : Tcl and Tk website
- Tcler's Wiki