Tcl的Java版 JTcl

jopen 14年前發布 | 22K 次閱讀 Tcl

JTcl 是一個 Tcl (Tool Command Language) 編程語言的 Java 實現保,支持 Tcl 8.4 的語法、命令。

JTcl 2.1.0 主要修復了以下bug:

  • A problem in 'info command' where too many leading namespace separators were returned was fixed.
  • An issue where an exception was thrown when opening a non-existent file in mode "a" or "a+" was fixed.
  • A problem where file event processing on an open socket would cause excessive CPU usage was fixed.
  • The 'hyde' module was included, which allow Java code to be compiled on-the-fly

Tcl(最早稱為“工具命令語言”"Tool Command Language",但是目前已經不是這個含義,不過我們仍然稱呼它為TCL)是一種 腳本語言。由John Ousterhout創建。 TCL很好學,功能很強大。TCL經常被用于快速原型開發,腳本編程,GUI和測試等方面。TCL念作“踢叩”(tickle)。Tcl的特性包括:

  • 任何東西都是一條命令,包括語法結構(for,if等)。
  • 任何事物都可以重新定義和重載。
  • 所有的數據類型都可以看作字符串。
  • 語法規則相當簡單。
  • 提供事件驅動給Socket和文件。基于時間或者用戶定義的事件也可以。
  • 動態的域定義。
  • 很容易用C, C++,或者Java擴展。
  • 解釋語言,代碼能夠動態的改變。
  • 完全的Unicode支持。
  • 平臺無關。Win32,UNIX,Mac 上都可以跑。
  • 和Windows的GUI緊密集成。Tk
  • 代碼緊湊,易于維護。

TCL本身在 8.6 以后提供面向對象的支持。因為語言本身很容易擴展到支持面向對象,所以在8.6之前存在許多C語言擴展提供面向對象能力,包括XOTcl, Incr Tcl 等。另外SNIT擴展本身就是用TCL寫的。

使用最廣泛的TCL擴展是TK。 TK提供了各種OS平臺下的圖形用戶界面GUI。連強大的Python語言都不單獨提供自己的GUI,而是提供接口適配到TK上。 另一個流行的擴展包是Expect. Expect提供了通過終端自動執行命令的能力,例如(passwd, ftp, telnet等命令驅動的外殼).

Tcl 支援擴充套件,這些擴充套件提供了額外的功能(像是 GUI,自動化,數據庫存取等)。

下面是一些 Tcl 擴充套件的列表:

  • tclodbc
  • mk4tcl
  • sqlite
  • Pgtcl, pgintcl
  • mysqltcl, msqltcl
  • AdabasTcl
  • FBSQL
  • ibtcl
  • Oratcl
  • Sybtcl
  • db2tcl

示例代碼:

#!/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>

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!