<<Up     Contents

Tcl

Tcl (originally from "Tool Command Language", but nonetheless usually lowercased) 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". It has some rather unique features:

While Tcl itself does not provide an object oriented framework the language itself can be extended to provide new features as required. Indeed, many C extensions exist that provide OO functionality, including the powerful XOTcl[?] and more traditional incr Tcl. Some Tcl-based OO extensions also exist.

The most famous extension is the Tk toolkit which allows one to write portable graphical user interfaces for a variety of operating systems.

A simple example, demonstrating event-based computing, follows.


# Simple echo-server that can handle multiple connections.

# This procedure is called when a client connects to the server
proc newConnection {sock addr port} {
    fconfigure $sock -blocking no -buffering line

    # handleData should be called with $sock as the parameter when data can
    # be read from the socket
    fileevent $sock readable "handleData $sock"

    return
}


proc handleData {sock} {
    set line [gets $sock]
    if {($line == "") && [eof $sock]} {
	close $sock
    } else {
	puts $sock $line
    }

    return
}


socket -server newConnection 20000
vwait forever

Another example using Tk (from A simple A/D clock (http://mini.net/tcl/2563.html)) and timer events, a digital clock in six lines of code:
 proc every {ms body} {
     eval $body
     after $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:

wikipedia.org dumped 2003-03-17 with terodump