Re: Package unloading



Derek Fountain wrote:
What is the relationship between the file "foo.tcl" and the package
"mypackage" ?

foo.tcl is a file full of procs that make up the functionality of mypackage. It's source'ed via autoload/auto_index when a proc in it is needed.

Ah. That's the key. Auto-loading is the feature of the problem making
this difficult.

I'd encourage you to examine just what it is you think auto-loading is
doing for you. Most of the justifications for it I can imagine have
passed from the scene. Simplest answer, at least long term, might be
"Stop Doing That".

If you do need or want to keep auto-loading, then you'll need to actually delete commands in order to force the auto-loader to load
them over again. If your package follows recommended conventions, that
should be a simple matter of [namespace delete ::mypackage]. [*]

Yes, I'm doing my package loading in what I thought was the "standard" way, but maybe it's only standard to me because that's how I've always done it.

I would describe it as doing packages in the "Tcl 7 way" myself. It
works, but there's better choices now.

I think adding something like Brian's 'reload' to my package loading is going to be the best way.

proc reload {p args} {
# auto_reset ;# Only if your edits invalidate a tclIndex file
catch {namespace delete ::$p} ;# safety if unconventional
package forget $p
package require $p {*}$args
}

[*] There is a third way. If you want to have auto-loading as a feature, but don't want the burden of [namespace delete] during iterative development, you can implement auto-loading for yourself with stub-proc definitions of your commands. Not making use of [unknown] or auto* at all.

--
| Don Porter Mathematical and Computational Sciences Division |
| donald.porter@xxxxxxxx Information Technology Laboratory |
| http://math.nist.gov/~DPorter/ NIST |
|______________________________________________________________________|
.



Relevant Pages

  • Re: Putting a binary extension in a namespace
    ... the commands in a non-global namespace. ... in one script end up ... A package typically defines each of its commands with a single ...
    (comp.lang.tcl)
  • Re: namespace import is slow
    ... In my case, the number of exported commands is about 8 per package, 10 ... I still don't understand well why "namespace import" is needed to be ... package require / use of fully qualified commands names ...
    (comp.lang.tcl)
  • Re: Namespace-relative package loading
    ... when loading the package from within an arbitrary namespace using: ... The first [package require msgcat] of any package will find and load some version of the msgcat package. ... The commands they ...
    (comp.lang.tcl)
  • Re: Question about packages / namespace import
    ... namespace import ral::* ... package provide flot 1.0 ... So that the commands from package "ral" get imported into ...
    (comp.lang.tcl)
  • Re: Question about packages / namespace import
    ... namespace import ral::* ... package provide flot 1.0 ... So that the commands from package "ral" get imported into ...
    (comp.lang.tcl)