Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2004-09-10
00:00 • Closed ticket [565823ffff]: inconsistent namespace import model plus 8 oth... artifact: b4a957e857 user: dgp
2002-06-07
21:00 • Ticket [565823ffff]: 4 changes artifact: 9671c9a2d8 user: dgp
13:54 • New ticket [565823ffff]. artifact: 69bb72baf2 user: dgp

inconsistent [namespace import] model

Closed / Invalid565823ffffffffffffffffffffffffffffffffffCreated 24 years agoUpdated 22 years ago
Descriptionplain2002-06-07 13:54:00
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?
dgpplain2002-06-07 21:00:58
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
dgpplain2004-09-10 00:00:01
Logged In: YES 
user_id=80530

both these features are
useful.  Withdrawing
this report.
Log in (anonymous is fine) to add a comment.