脚本语言 Tcl 介绍

openkk 12年前
     <p><strong>Tcl</strong>(最早称为“工具命令语言”"Tool Command Language",但是目前已经不是这个含义,不过我们仍然称呼它为TCL)是一种 脚本语言。由<span class="new">John Ousterhout</span>创建。 TCL很好学,功能很强大。TCL经常被用于<span class="new">快速原型开发</span>,脚本编程,GUI和测试等方面。TCL念作“踢叩”(tickle)。Tcl的特性包括:</p>    <ul>     <li>任何东西都是一条命令,包括语法结构(for,if等)。</li>     <li>任何事物都可以重新定义和重载。</li>     <li>所有的数据类型都可以看作字符串。</li>     <li>语法规则相当简单。</li>     <li>提供事件驱动给Socket和文件。基于时间或者用户定义的事件也可以。</li>     <li>动态的域定义。</li>     <li>很容易用C, C++,或者Java扩展。</li>     <li>解释语言,代码能够动态的改变。</li>     <li>完全的Unicode支持。</li>     <li>平台无关。<span class="mw-redirect">Win32</span>,UNIX,<span class="mw-redirect">Mac</span> 上都可以跑。</li>     <li>和Windows的GUI紧密集成。Tk</li>     <li>代码紧凑,易于维护。</li>    </ul>    <p>TCL本身在 8.6 以后提供面向对象的支持。因为语言本身很容易扩展到支持面向对象,所以在8.6之前存在许多C语言扩展提供面向对象能力,包括XOTcl, Incr Tcl 等。另外SNIT扩展本身就是用TCL写的。</p>    <p>使用最广泛的TCL扩展是TK。 TK提供了各种OS平台下的图形用户界面GUI。连强大的Python语言都不单独提供自己的GUI,而是提供接口适配到TK上。 另一个流行的扩展包是Expect. Expect提供了通过终端自动执行命令的能力,例如(passwd, ftp, telnet等命令驱动的外壳).</p>    <p>Tcl 支援扩充套件,这些扩充套件提供了额外的功能(像是 GUI,自动化,数据库存取等)。</p>    <p>下面是一些 Tcl 扩充套件的列表:</p>    <ul>     <li>tclodbc</li>     <li>mk4tcl</li>     <li>sqlite</li>     <li>Pgtcl, pgintcl</li>     <li>mysqltcl, msqltcl</li>     <li>AdabasTcl</li>     <li>FBSQL</li>     <li>ibtcl</li>     <li>Oratcl</li>     <li>Sybtcl</li>     <li>db2tcl</li>    </ul>    <p>示例代码:</p>    <pre class="brush:shell; toolbar: true; auto-links: false;">#!/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</pre>    <p><strong>项目主页:</strong><a href="http://www.open-open.com/lib/view/home/1325317352624" target="_blank">http://www.open-open.com/lib/view/home/1325317352624</a></p>    <p></p>