Tcl

示例

下面是TCL程序的例子：
#!/bin/sh
# next line restarts using tclsh in path \
exec tclsh $0 ${1+"$@"}

# echo server that can handle multiple
# simultaneous connections.

proc newConnection { sock addr port } {

     # 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
     }
}

# handle all connections to port given
# as argument when server was invoked
# by calling newConnection
set port [ lindex $argv 0 ]
socket -server newConnection $port

# enter the event loop by waiting
# on a dummy variable that is otherwise
# unused.
vwait forever
另外一个Tk 的例子（来自A simple A/D clock）它使用了定时器时间，3行就显示了一个时钟。
 proc every {ms body} {eval $body; after $ms [info level 0]}
 pack [label .clock -textvar time]
 every 1000 {set ::time [clock format [clock sec] -format %H:%M:%S]} ;# RS
解释：第一行定义了过程every， 每隔ms毫秒，就重新执行body代码。第二行创建了标签其内容由time变量决定。第3行中设置定时器，time变量从当前时间中每秒更新一次。