Menu

#1897 inconsistent [namespace import] model

obsolete: 8.4a5
closed-invalid
5
2004-09-09
2002-06-07
Don Porter
No

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?

Discussion

  • Don Porter

    Don Porter - 2002-06-07

    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

     
  • Don Porter

    Don Porter - 2004-09-09

    Logged In: YES
    user_id=80530

    both these features are
    useful. Withdrawing
    this report.

     
  • Don Porter

    Don Porter - 2004-09-09
    • assigned_to: msofer --> dgp
    • status: open --> closed-invalid