Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2007-10-31
23:55 • Ticket [458892ffff] Legal but irregular names ?? status still Open with 4 ot... artifact: 5fc8820475 user: msofer
23:35 • Ticket [458892ffff]: 4 changes artifact: c37e8e5250 user: dgp
2004-09-10
06:10 • Ticket [458892ffff]: 4 changes artifact: 9c94040071 user: dgp
2003-11-13
08:37 • Ticket [458892ffff]: 1 change artifact: b9b8043404 user: dgp
2003-01-21
06:11 • Ticket [458892ffff]: 4 changes artifact: a176dce0c2 user: mic42
2001-09-06
07:34 • Ticket [458892ffff]: 4 changes artifact: 936bac0daa user: dgp
2001-09-05
20:51 • New ticket [458892ffff]. artifact: 4f05f32554 user: msofer

Legal but irregular names ??

Open458892ffffffffffffffffffffffffffffffffffCreated 25 years agoUpdated 19 years ago
Descriptionplain2001-09-05 20:51:53
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.
dgpplain2001-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 "".
mic42plain2003-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 Ticket [458892ffff]: 1 change [History diff]2003-11-13 08:37:25
dgpplain2004-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.
dgpplain2007-10-31 23:35:26
Logged In: YES 
user_id=80530
Originator: NO


status?
msoferplain2007-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
Log in (anonymous is fine) to add a comment.