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:
The most popular Tcl extension is the Tk toolkit, which allows one to write portable graphical user interfaces 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 mode fconfigure $sock -blocking no -buffering line}# call handleData when socket is readable fileevent $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.
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