Tcl(发音tickle)是一种脚本语言。由John Ousterhout创建。TCL经常被用于快速原型开发 RAD、脚本编程、GUI编程和测试等方面。
![]() | |
编程范型 | 多泛型、面向对象、函数式、过程式、事件驱动、指令式 |
---|---|
設計者 | John Ousterhout |
實作者 | John Ousterhout、Tcl核心團隊 |
发行时间 | 1988年 |
目前版本 |
![]() |
型態系統 | 动态类型、万物皆可视作字符串 |
文件扩展名 | .tcl |
網站 | www.tcl.tk |
主要實作產品 | |
ActiveTcl | |
啟發語言 | |
AWK、Lisp | |
影響語言 | |
PowerShell[2]、Tea |
Tcl 的特性包括:
旧版 Tcl 没有内置面向对象功能,因此许多 OO 库以扩展形式涌现出来,如 incr Tcl 和 XOTcl,甚至存在纯脚本编写的 OO 包,如 Snit 和 STOOOP(simple Tcl-only object-oriented programming),8.6 版本在内核中提供了 OO 功能[4]。
Safe-Tcl 是功能受限的 Tcl 子集。文件系统访问受限,任意系统命令禁止执行。它使用双解释器模型,在“不可信解释器”中运行不可信脚本中的代码。由 Nathaniel Borenstein 和 Marshall Rose 设计,借以在电子邮件中包含活动信息,当支持 application/safe-tcl 与 multipart-enabled-mail 时,Safe-Tcl 即可包含于电子邮件中。Safe-Tcl 功能已整合在标准 Tcl/Tk 发布中。[5][6]
Tcl 支持扩展包,这些扩展包提供了附加功能(像是GUI,终端程序自动化,数据库访问等)。常用的扩展包有:
下面是TCL程序的例子:
#!/bin/sh
# next line restarts using tclsh in path \
exec tclsh $0 ${1+"[email protected]"}
# 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变量从当前时间中每秒更新一次。
維基教科書中的相關電子教程:Tcl 编程 |
维基共享资源中相关的多媒体资源:Tcl |