Re: [TCL] Help debugging behavior in new source command
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

Re: [TCL] Help debugging behavior in new source command

From: Don Porter <dgp@email.nist.gov>
Date: Thu Apr 13 2006 - 17:49:09 CEST

In article <443e700e$1@usenet01.boi.hp.com>, Andrew Falanga wrote:
> I'm working on a new source command that will manage a list of loaded
> libraries for me. The code for the new source command is:

Let us count the opportunities for improvement...

> rename source _source
>
> proc source { pathToFile } {
> global libraryIndex
> if { ![file exists $pathToFile] } {
> Log "File: $pathToFile does not exist"
> exit
> }

Process exit is a pretty severe reaction to a missing file.
Sure that's what you want?

> uplevel #0 [list _source] $pathToFile

This should be:

        uplevel 1 [list _source $pathToFile]

The revised [list] arguments are in order to support values
of $pathToFile that contain spaces. That's the whole point of
[list] quoting. Just [list _source] alone is essentially pointless.

The change in the "level" argument makes sure that your replacement
[source] command sources in the same context as the original one
would. With [uplevel #0] you're forcing it into the global context,
and some uses of [source] will not be happy with that as you discovered.

>
> regsub -all {/} $pathToFile " " pathToFile
>
> lappend libraryIndex [lindex $pathToFile end]

Wouldn't it be easier to do:

        lappend libraryIndex [file tail $pathToFile]

> }

-- 
| Don Porter          Mathematical and Computational Sciences Division |
| donald.porter@nist.gov             Information Technology Laboratory |
| http://math.nist.gov/~DPorter/                                  NIST |
|______________________________________________________________________|
Received on Sun Apr 30 03:10:36 2006