开发者

how to use procedures in package with different versions in tcl

My question is i have created two versions that is 1.1 1.2 packages i have same procedures in 1.1 and 1.2 but i modified a new version of proced开发者_Go百科ure in 1.2.

Now my question is suppose to want acess old version (1.1) procedure. How i do?


Each interpreter can only load a single version of any particular package; it's assumed that their namespaces clash so that it isn't possible to load two versions of the same thing at once.

However, you might be able to load the other version (using the -exact option to force the less-recent version) in a sub-interpreter. This is more likely to work with pure scripted packages than those which have a C component (that depends on the OS's dynamic library loader being happy with these things; some are, some aren't.)

interp create subinterp
subinterp eval {
    package require -exact mypackage 1.1
}
subinterp eval mySquare 3

This might or might not be what you're after though; interpreters are very strongly isolated from each other, so access to other things going on in the master interpreter would require setting up aliases…


Use the -exact flag in the package require statement:

package require -exact mypackage 1.1

UPDATE: I don't recommend having different versions of the same package loaded one after another. However, you can load the first version, do your business, unload it, then load the second version and do your business. In code:

package require -exact mypackage 1.1
mySquare 2
package forget mypackage

package require -exact mypackage 1.2
mySquare 3
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜