跳转到内容

Incr Tcl

维基百科,自由的百科全书
Itcl
编程范型多範式: 面向對象, 函數, 指令, 事件驅動
設計者Michael McLennan
實作者Michael McLennan
发行时间1993
当前版本
  • Itcl4.1.1(2017年12月21日;穩定版本)
編輯維基數據鏈接
類型系統動態類型, 所有物件都可以被當做字符串來處理
網站incrtcl.sourceforge.net/itcl/ 編輯維基數據鏈接
受影响于
Tcl, C++

incr Tcl (incr,即increase,在英文中表示"+", 這個名字是由 "C++"而來, 簡寫作 "itcl"),是Tcl編程語言的面向對象編程的擴展包。它被廣泛使用Tcl編程人員廣泛使用。Itcl有兩種使用方式,一是軟體包(package),可被Tcl程序動態載入;一是作為單獨的語言,有自己的解譯器(standalone interpreter)。

概述

[编辑]

特點

[编辑]

命名空間的支持

[编辑]

Itcl 允許使用命名空間(namespace)來組織的命令和變量。

例:

    package require Itcl
    
    itcl::class Toaster {
        variable crumbs 0
        method toast {nslices} {
            if {$crumbs > 50} {
                error "== FIRE! FIRE! =="
            }
            set crumbs [expr $crumbs+4*$nslices]
        }
        method clean {} {
            set crumbs 0
        }
    }
    
    itcl::class SmartToaster {
        inherit Toaster
        method toast {nslices} {
            if {$crumbs > 40} {
                clean
            }
            return [chain $nslices]
        }
    }
    
    set toaster [SmartToaster #auto]
    $toaster toast 2

C代碼的整合

[编辑]

Itcl (跟Tcl一樣) 內置有C代碼整合支持,讓C代碼整合為Itcl類。

相關參考

[编辑]

外部連結

[编辑]