Friday 24 February 2017

TCL PACKAGES

Packages:
•       Tcl provides a more powerful mechanism for handling reusable units of code called packages
•       A package is simply a bundle of files implementing some functionality, along with a name that   
         identifies the package, and a version number that allows multiple versions of the same
         package to
         be present 
•       A package can be a collection of Tcl scripts, or a binary library, or a combination of both 

How to Create Package:
•       Adding a package provide statement to your script 
•       Creating a pkgIndex.tcl file. 
•       Installing the package where it can be found by Tcl. 
•       Commands
•       package require ?-exact? name ?version?
•       package provide name ?version?

Sample Packages:
Example:
package require TclUtils


1. Use of package command?
Package is similar to libraries except that they require explicit loading.

2..Use of package require command?
Package require command organizes sets of procedures under a single name, and lets you request packages by name and revision number.

3. What are the possible package require problem?
Say package A and package B both define procedure name sum. If these two packages are loaded and each contains same proc name, then the last package loaded will define the procedure, even it is different from the first procedure.


Solution: namespaces will help alleviate this problem.


How to Create a package in TCL see the below link.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.