When I [namespace import ::ns::foo], it is clear that I
create a new command "foo" in the current namespace
which refers to the command ::ns::foo. But precisely
what does it refer to? Does it refer to the *name*
::ns::foo, or does it refer to the command that currently
has the name ::ns::foo ?
[namespace import] will not work on an undefined name,
so it seems to indicate that the reference is to the actual
command, not the name. Furthermore, there are other
ways to reference commands by name, including "wrapping"
procs, and [interp alias].
But, Tcl appears to try to have it both ways. The
implementation
of [rename] does transfer import links from the old name to
the new name, preserving the references to the command
itself.
But! the implementation of Tcl_CreateObjCommand also
transfers import links from the original definition to
the new
definition when a command name is reused, preserving
the references to the command name.
That seems inconsistent to me. Is it really intended
to do both.
If so, can it be better documented?
Logged In: YES
user_id=80530
oops forgot to attach the illustrative examples.
reference follows redefinition:
% namespace eval one {
namespace export foo
proc foo {} {puts foo}
}
% namespace eval two namespace import ::one::foo
% two::foo
foo
% proc one::foo {} {puts new}
% two::foo
new
But reference also follow rename:
% namespace eval one {
namespace export foo
proc foo {} {puts foo}
}
% namespace eval two namespace import ::one::foo
% two::foo
foo
% namespace origin two::foo
::one::foo
% rename one::foo one::bar
% two::foo
foo
% namespace origin two::foo
::one::bar
Logged In: YES
user_id=80530
both these features are
useful. Withdrawing
this report.