[TCL] Strange behavior, or so I think, for package require
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

[TCL] Strange behavior, or so I think, for package require

From: Andrew Falanga <not_real@hp.com>
Date: Mon Apr 03 2006 - 17:28:45 CEST

Hello,

I'm trying to debug why this the following is happening. I have a
library in which I try to keep from performing a package require to many
times. Mostly, this is to avoid errors when troubleshooting in the
tclsh. My code looks like

if { [lsearch [package names] "*cmdline*"] < 0 } {
   Log "cmdline is not present in package list"
} else {
   Log "package cmdline is present in package list"
}

if { ![string match "*/path/to/tcllib/*" $auto_path] } {
   lappend auto_path /path/to/tcllib/
}

if { [lsearch [package names] "*cmdline*"] < 0 } {
   Log "cmdline is not present in package list"
} else {
   Log "package cmdline is present in package list"
}

if { ![string match "*tclxml3.0*" $auto_path] } {
   lappend auto_path /path/to/tclxml3.0
}

if { [lsearch [package names] "*xml*"] < 0 } {
   package require xml
}

if { [lsearch [package names] "*cmdline*"] < 0 } {
   Log "cmdline is not present in package list"
} else {
   Log "package cmdline is present in package list"
}

if { [lsearch [package names] "*cmdline*"] < 0 } {
   package require cmdline
}

The conditionals that do nothing but produce output are for debugging
purposes only and produce the following output:

cmdline is not present in package list
cmdline is not present in package list
package cmdline is present in package list

Why? By the time of that third output, the package require cmdline
hasn't been executed yet so why is it present? Also, although my
conditional is true, the procedures that use procs in the cmdline
library, fail because the procedures haven't been included to the
interpreter.

Why does that first call to package require seem to "include" virtually
all possible packages in the auto_path variable?

---------------------------------------------
Andrew R. Falanga (a non-HP employee)
Hewlett-Packard Company
11311 Chinden Blvd.
Boise, Idaho
---------------------------------------------
Please note: The e-mail address is purposely
mangled. I do not wish my account at HP to
become a spam haven.
Received on Sun Apr 30 02:57:38 2006