3

I am new to TCL and am struggling with accessing other modules. The SOURCE command helped me include other code that I have written in a TCL program. However, I think I have a problem with accessing libraries of code.

For example, when I reference a math function, it is not found. I think there must be something I need to do to include where the math library is on my computer in the search for a program called via tchsh85.

invalid command name "::math::statistics::mv-ols"
None of these directories exist on my computer: info library= C:/Tcl/lib/tcl8.5 auto_path= C:/Tcl/lib/tcl8.5 C:/Tcl/lib c:/tcl/lib/teapot/package/win32-x86_64/lib c:/tcl/lib/teapot/package/tcl/lib tcl library= C:/Tcl/lib/tcl8.5 auto_index= source C:/Tcl/lib/tcl8.5/word.tcl auto_index= source C:/Tcl/lib/tcl8.5/tm.tcl auto_index= source C:/Tcl/lib/tcl8.5/tm.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/parray.tcl auto_index= source C:/Tcl/lib/tcl8.5/history.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/history.tcl auto_index= source C:/Tcl/lib/tcl8.5/package.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/history.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/word.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/word.tcl auto_index= source C:/Tcl/lib/tcl8.5/package.tcl auto_index= source C:/Tcl/lib/tcl8.5/tm.tcl auto_index= source C:/Tcl/lib/tcl8.5/auto.tcl auto_index= source C:/Tcl/lib/tcl8.5/auto.tcl auto_index= source C:/Tcl/lib/tcl8.5/auto.tcl auto_index= source C:/Tcl/lib/tcl8.5/auto.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/auto.tcl auto_index= source C:/Tcl/lib/tcl8.5/history.tcl auto_index= source C:/Tcl/lib/tcl8.5/auto.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/history.tcl auto_index= source C:/Tcl/lib/tcl8.5/package.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/auto.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/auto.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/history.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/tm.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/auto.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/auto.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/word.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/package.tcl auto_index= source C:/Tcl/lib/tcl8.5/auto.tcl auto_index= source C:/Tcl/lib/tcl8.5/history.tcl auto_index= source C:/Tcl/lib/tcl8.5/package.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/word.tcl auto_index= source C:/Tcl/lib/tcl8.5/history.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/auto.tcl auto_index= source C:/Tcl/lib/tcl8.5/history.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl auto_index= source C:/Tcl/lib/tcl8.5/tm.tcl auto_index= source C:/Tcl/lib/tcl8.5/tm.tcl auto_index= source C:/Tcl/lib/tcl8.5/safe.tcl

I received this answer: ::math::statistics is part of TCLlib. To check if you have it installed, type

package require tcllib and if it is installed, it will tell you the version number. If it's not installed, you can use Teacup to install it for you.

I tried the code:

catch {package require nonexistentName}
 package names
puts "[package names]"

and I received:

Thread logger img::pixmap TclOO tablelist_tile struct::tree opt tcltest img::ico img::pcx struct::set msgcat pngtcl tablelist::common ftp Tclx trsync tdom img::sgi report comm dde Mk4tcl img::sun img::gif img::window textutil cmdline csv img::tga Img img::png Tktable Itk Ttrace tipstack zlibtcl img::base platform fileutil Tk vfs ActiveTcl http tbcload Memchan style struct::graph tablelist treectrl struct::queue img::jpeg activestate::teapot::link img::bmp registry jpegtcl tdomhtml tooltip snit img::ppm struct::stack tcl::tommath img::tiff tls widget struct img::xpm md5 BWidget img::xbm log starkit Tcl Trf tifftcl Itcl img::ps sqlite3 base64 trofs
0.7

I may not understand TCL but in other languages I have used, there a way to set up a list of directories or files to be searched in a certain order for called code. It seems to me that I need to tell tclsh85 where to look.

I downloaded tcl 8.5.13 and BWidget 1.9.6 from ActiveState I installed tcl and I unpacked BWidget on my computer, but it is in a different location than my tcl programs. Is math part of that? If not, what should I download? As I am running on Windows Vista, I prefer to just get an executable version rather than something that I need to build. I can create tcl programs and as long as they are self contained or if I can use SOURCE, all is well. Where I am having trouble is calling code outside my program.

I worry that auto_path needs to be set up for my environment as it does not correspond to anything on my computer now.

Please answer assuming I do not know anything about how tcl works. I am trying to teach myself (with some help from internet documentation and people who will answer questons).

Thank you.

GrAnd
  • 10,141
  • 3
  • 31
  • 43
user1985580
  • 61
  • 2
  • 4

1 Answers1

14

Ok, I try to summarize your questions:

You want to know how to install the packages you need.

You can either use teacup to install them, for example teacup install math::statistics, which should do the job, or download tcllib and install it. The installation of Tcllib is straight forward and should automatically choose the right path where it should be installed. To use a library in your code you just need to do package require math::statistics

You want to know how you could add directories where Tcl should look for libraries.

Depending on what kind of lib it is, there are 2 possibilities:

  • if there is a file called pkgIndex.tcl or autoIndex then you have to modify the auto_path variable. This can be done with lappend auto_path path/to/the/files.
  • If there is only a single file ending with .tm, then it is a little bit more complex: you have to add the right parent directory. So if you have a statistics.tm file that lies in /some/directory/math/statistics.tm and this is the math::statistics package, then the appropriate directory is /some/directory. You can add it by using ::tcl::tm::path add /some/directory.

Such a thing is almost never necessary, and because you managed it to install BWidgets successful, the auto_path should be fine for you. Please note that Tcl uses (like many other languages, including Java, Perl etc.) a single / as path delimiter instead of the usual windows \.

You prefer having a single file executable Yes, this is possible, but you should first understand how to get the packages, what files are needed etc. The technology for a single file Tcl distribution is called Starkit, a very useful thing, but you should be familiar with Tcl already.

Johannes Kuhn
  • 14,778
  • 4
  • 49
  • 73
  • 1
    Please note that `teacup` is not a Tcl command, it is meant to be run from the command line (Start->Run->cmd). `teacup update` will install all available libs, but this may take a while. – Johannes Kuhn Jan 19 '13 at 00:13