Encyclopedia > Tcl programming language

  Article Content

Tcl

Redirected from Tcl programming language

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:

  • Everything is a command, including language structures.
  • Everything can be dynamically replaced and overridden.
  • All data types can be handled as if they were strings, including code.
  • Extremely simple syntactical rules, which everything follows.
  • Heavily event-driven.
  • Dynamic scope.
  • High extensibility (with C, C++, Java and Tcl)
  • interpreted language, means you can create code on the fly and execute it
  • Full Unicode support
  • platform independent (Win32, UNIX, Mac, etc.)
  • integration with window-interface Tk
  • easy maintenance of code, as it is very short

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)) 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:



All Wikipedia text is available under the terms of the GNU Free Documentation License

 
  Search Encyclopedia

Search over one million articles, find something about almost anything!
 
 
  
  Featured Article
242

... 2nd century - 3rd century - 4th century Decades: 190s 200s 210s 220s 230s - 240s - 250s 260s 270s 280s 290s Years: 237 238 239 240 241 - 242 - 243 ...

 
 
 
This page was created in 41.1 ms