|
2021-05-04
| ||
| 12:59 | • Ticket [c9ca7bca7e] import proc from namespace with other name status still ... artifact: 987135153f user: pooryorick | |
|
2016-10-09
| ||
| 15:46 | • Ticket [c9ca7bca7e]: 4 changes artifact: cfdd2a744c user: dkf | |
|
2016-09-18
| ||
| 19:21 | • Ticket [c9ca7bca7e]: 4 changes artifact: 8cef93a49e user: dgp | |
| 00:17 | • New ticket [c9ca7bca7e]. artifact: 6009146fa7 user: anonymous | |
import proc from namespace with other name
In Tcl, there is no possibility to import proc's from other namespaces with other names to avoid collisions. For example, something like this:
namespace import_as ::private_namespace:my_proc1 my_proc2Using this command, there is a copy of my_proc1 with name my_proc2 in the current namespace
I strongly agree.
I've always imagined this as a new option to
[namespace import]:
namespace eval my {
namespace import -as bar ::orig::foo
}
so that then ::my::bar is an import of ::orig::foo
This is more direct and tidier than the
combination of [namespace import] and [rename]s
that is otherwise needed.
The only issue is that we're currently having namespace import working on a whole set of stuff defined by a list of patterns; this renaming-as-we-go only really works with a single command.
Not that it's a bad idea at all. Just needs documenting carefully.
In the meantime, this can be trivially implemented as a script:
proc import {link ns target} {
set tmpns [info cmdcount]
try {
namespace eval $tmpns [list namespace import ${ns}::*]
namespace eval $tmpns [list ::rename $target [
uplevel 1 {namespace current}]::$link]
} finally {
namespace delete $tmpns
}
return
}
Granted, importing all exported names is not so efficient, but it skirts pattern-matching issues.