Clever Geek Handbook
📜 ⬆️ ⬇️

Incr Tcl

Incr TCL (ITCL) is the first of the object-oriented extensions of the TCL language. Partially implemented in C language. Using it, a library of graphical widgets incr Widgets (iWidgets) was written. The name of this extension is a kind of “translation” of the C ++ name into Tcl , the incr command, like the ++ operation, increases its argument by 1.

Along with XOtcl and SNIT, it is one of the three most popular object-oriented extensions of Tcl [1] .

Content

Commands

ITCL - defines the following commands:

  • itcl :: body - defines and redefines the body of methods;
  • itcl :: class - a description of the class, see the example below;
  • itcl :: code - gives access to private members of the class, and should not be used by an application programmer under normal program design;
  • itcl :: configbody - allows you to bind one or more configurators (something like SQL triggers ) to a class variable, see the example below;
  • itcl :: delete - deletes objects, classes and namespaces;
  • itcl :: ensemble - creates and modifies composite commands, see details below;
  • itcl :: find - creates a list of classes and objects of the current namespace that satisfy the pattern;
  • itcl :: local - creates a local instance of the class (inside the procedure definition);
  • itcl :: scope - limits the access to the variable to the current context for passing to non-object-oriented Tcl / Tk commands [2] .
  • itcl :: is - Checks if a variable belongs to a class.

Class Definition Example

An example is the object wrapper over Tcl text files. The use of configurators is shown.

  class File {

     # describe and set initial values
     # local variables
     private variable fid ""

     public variable name ""
     public variable access "r"

     # define constructor and destructor
     constructor { args } {
         eval configure $ args
         # configure word activates configurators
     }

     destructor {
         if { $ fid ! = "" } {
             close $ fid
         }
     }

     # describe class methods
     method get {}
     method put { line }
     method eof {}
 }

 # define body methods

 body File :: get {} {
     return [ gets $ fid ]
 }
 body File :: put { line } {
     puts $ fid $ line
 }
 body File :: eof {} {
     return [ :: eof $ fid ]
 }

 # define the configurator for
 # global variable name
 # configurator for access not created

 configbody File :: name {
     if { $ fid ! = "" } {
         close $ fid
     }
     set fid [ open $ name $ access ]
 }

 #
 # File class in action:
 #

 # create an object
 File x

 # configure its name
 x configure - name / etc / passwd

 # display the contents of the file, line by line
 while { !  [ x eof ]} {
     puts "=> [x get]"
 }

 # delete the object
 delete object x

Various members of the class are described with the following classes, commands available inside the definition: constructor , destructor , method , proc (unlike a method, it is not inherited), variable , common (similar to static in C ++), public , protected , private , set and array Inheritance is specified by the inherit command. Multiple inheritance is allowed. All methods are virtual. When defining a class, you can use metaprogramming techniques, for example, to define several local variables in a loop, along with set and get methods of access to them [3] .

Compound Commands

A composite team (or ensemble) is defined as:

  ensemble nameSost team arg arg ...

or

  ensemble nameSost {
     part namePart arguments body
     ... 
     ensemble nameSubSost {
         part name Subpart arguments body
         ... 
     }
 }

Tcl ensembles are a convenient syntax add-on over the standard namespace ensemble Tcl mechanism. This mechanism allows you to group several teams into one namespace - an ensemble. Appeal to the team - part of the ensemble looks like:

  nameCost namePart of arguments

Any number of ensemble constructions with the same name can exist; all parts defined in them will be included in the same ensemble [4] .

Links

  • incrtcl.sourceforge.net (Eng.) - Incr Tcl Project
  • incrtcl.sourceforge.net/iwidgets/iwidgets.html - incr Widgets
  • www.tcl.tk/man/itcl3.1 (English) - official documentation
  • wiki.tcl.tk/62 (English) - incr Tcl on the Tcl Wiki

See also

  • Tcl
  • Hotcl
  • Snit
  • STOOOP

Notes

  1. ↑ Clif Flynt. Ch. 9. Basic Object Oriented Programming in Tcl // Tcl / Tk: A Developer's Guide. - 3-rd edition. - Elsevier, 2012 .-- P. 263. - 792 p. - ISBN 978-0-12-384717-1 .
  2. ↑ implementation details see man itcl :: scope
  3. ↑ see Automatic get / set methods for an itcl class
  4. ↑ namespace-specific behavior

Literature

  • Chad smith. Incr Tcl / Tk from the ground up. - Osborne / McGraw-Hill, 2000 .-- 746 p. - ISBN 0-07-212106-8 .
  • Clif Flynt. 17.1 [incr Tcl] // Tcl / Tk: A Developer's Guide . - Elsevier, 2012 .-- S. 667-670. - 817 p. - ISBN 9780123847188 .


Source - https://ru.wikipedia.org/w/index.php?title=Incr_Tcl&oldid=79202526


More articles:

  • Hakuasheva, Madina Andreevna
  • First Live Recordings
  • Foxes (Tver Oblast)
  • Verzhbitsky, Grigory Afanasyevich
  • Udabnopithek
  • Middle (river flows into the Bering Sea)
  • Yalutsevichi Village Council
  • Schuchenka (river)
  • Soloukhin, Rem Ivanovich
  • Jamaica at the 2012 Summer Olympics

All articles

Clever Geek | 2019