Tcl Source Code

View Ticket
Login
Ticket UUID: 458892
Title: Legal but irregular names ??
Type: Bug Created on: 2001-09-05 20:51:53
Submitter: msofer Assigned to: msofer
Subsystem: 21. [namespace] Severity:
Priority: 3 Low Last modified: 2007-10-31 23:55:46
Status: Open Closed by:
Resolution: None Closed on:
Version: obsolete: 8.3.3
Description:
The character ":" is a legal character for variable and
command names - with the proviso that it cannot appear
doubled:
   a::b
is the name of variable (or command) 'a' in the
namespace 'b'.

Variable and command names that start with ":" are
legal, but behave differently: the following script
     set a 1 
     set :a 2 
     namespace eval tst {
         proc tst var { 
             set [uplevel namespace current]::$var 
          }
      }
      puts "($a [set a] [tst::tst a] ${:a} [set :a]
[tst::tst :a])"

returns (1 1 1 2 2 1) instead of (1 1 1 2 2 2).

I see two possible fixes to this:
  - stop interpreting any sequence of two or more ":"
as a 
     namespace separator.
  - forbid ":" as first character in a name

Namespace names probably show similar irregularities,
with a vengeance.
User Comments:
dgp added on 2001-09-06 07:34:07:
Logged In: YES 
user_id=80530

Note that the rule of collapsing all runs of 2 or more
':' into one namespace separator also makes it difficult
to make use of a namespace named "".

mic42 added on 2003-01-21 06:11:25:
Logged In: YES 
user_id=302287

Namespace names have similar irregularities:

% namespace eval ::foo::bar: {set a 1; namespace current}
::foo::bar:
% namespace eval ::foo::bar: {namespace eval baz {set a 1;
namespace current}
::foo::bar:::baz

% namespace children ::foo::bar:
::foo::bar:::baz

% set ::foo::bar:::baz::a
can't read "::foo::bar:::baz::a": no such variable

% namespace eval ::foo::bar: { set baz::a}
1

The man page is unclear about this, it states that : in
names are ignored, but they are not.
% namespace eval ::foo::bar:baz {namespace current}
::foo::bar:baz

So, introspection does work for peculiar namespaces, but
using the results of this introspection does not always work
as expected.

dgp added on 2004-09-10 06:10:28:
Logged In: YES 
user_id=80530


Re-reading this, it looks at lot like
TIP 184 (Bug 600812) to me.
That let us create variables we
couldn't act on.

This flaw also lets us create things
with names we can't act on.

dgp added on 2007-10-31 23:35:26:
Logged In: YES 
user_id=80530
Originator: NO


status?

msofer added on 2007-10-31 23:55:46:
Logged In: YES 
user_id=148712
Originator: YES

Status unchanged, IMO we have to live with this until 9.0:

* The identity of a:::b and a::b is longstanding and documented, probably used at lots of code in the wild in some variety of
   set FQname [namespace current]::$name

* Every char is valid in any name in Tcl; not sure it is advisable to start considering exceptions