Tcl
Tcl (originally from "Tool Command Language", but nonetheless conventionally rendered as "Tcl") is a scripting language created by John Ousterhout that is generally thought to be easy to learn, but powerful in the right hands. It is most commonly used for rapid prototyping, scripted applications, GUIs and testing. The name is commonly pronounced as "tickle". Tcl's features include:
- Everything is a command, including language structures.
- 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.
- Dynamic scope
- Readily extensible (with C, C++, Java and Tcl)
- Interpreted language, code can be created and modified dynamically
- Full Unicode support
- Platform independent (Win32, UNIX, Mac, etc.)
- Close integration with windowing (GUI) interface Tk
- Code is easy to maintain. Tcl scripts are often more compact and readable than functionally equivalent code in other languages
The most popular Tcl extension is the Tk toolkit, which provides a graphical user interface library for a variety of operating systems.
A simple working example, demonstrating event-based handling of a socket, follows.
exec tclsh $0 ${1+"$@"}
- !/bin/sh
- next line restarts using tclsh in path \\
proc newConnection { sock addr port } {
- echo server that can handle multiple
- simultaneous connections.
# client connections will be handled in# line-buffered, non-blocking modefconfigure $sock -blocking no -buffering line
# call handleData when socket is readablefileevent $sock readable [ list handleData $sock ]}proc handleData { sock } {
puts $sock [ gets $sock ]if { [ eof $sock ] } {close $sock}}
set port [ lindex $argv 0 ] socket -server newConnection $port
- handle all connections to port given
- as argument when server was invoked
- by calling newConnection
vwait forever
- enter the event loop by waiting
- on a dummy variable that is otherwise
- unused.
Another example using Tk (from A simple A/D clock) and timer events, a digital clock in six lines of code:
proc every {ms body} {eval $bodyafter $ms [list every $ms $body]}pack [label .clock -textvar time]every 1000 {set ::time [clock format [clock sec] -format %H:%M:%S]} ;# RS
External links
- Tcl Documentation
- Main Tcl developer site
- ActiveState's Tcl distribution with extensions
- Tcl FAQ
- Tcl'ers Wiki
- Tcl Contributed Sources Archive
- Citations from CiteSeer
| Programming languages |
| Ada | Algol | APL | BASIC | C | C++ | C# | Cg | COBOL | Common Lisp | ColdFusion | Delphi | Eiffel | Forth | FORTRAN | Haskell | Java | JavaScript | Jython | Lisp | Logo | Mesa | ML | Modula-2 | Oberon | Objective-C | Objective Caml | Pascal | Perl | PHP | PL/I | PostScript | Powerbuilder | Prolog | Python | QBASIC | REXX | Ruby | Scheme | Smalltalk | Tcl/Tk | Visual Basic |