Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 83669c9d0864888279df5b9dde97c22875e3d45f
Ticket: 959786ffffffffffffffffffffffffffffffffff
bug in varName resolution
User & Date: msofer on 2004-05-25 09:12:10
Changes

  1. icomment:
    Logged In: YES 
    user_id=148712
    
    This was indeed broken by the fix to Bug #959052. There are
    several possible fixes, they are the subject of the next post.
    
    The code above is very non-standard, and does not work quite
    as (I guess that) the author intended in tcl8.x (due to the
    documentation bug #959831).
    
    What happens in that code is:
    
    (1) 'global' enters "name" in the variable hash-table for
    foo, and creates a local variable called "name" linked to
    it. ::foo::name is undefined, and 
    'info vars ::foo::name' returns {}
    
    (2) when 'set foo::name 1' is called, the variable name
    resolution proceeds as follows:
        - "name" is looked up in the ::foo::foo namespace; not found
        - "name" is looked up in the ::foo namespace; found (by
    bug #959052)
    
    That code works "by chance":
    
      % info patch
      8.3.4
      %  namespace eval foo {}
      % namespace eval foo::foo {set name 2}
      2
      % proc foo::bar {} {
              global foo::name
              set foo::name 1
          }
      %  foo::bar
      1
      % set foo::name
      can't read "foo::name": no such variable
      %  set foo::foo::name
      1
    
    In tcl8.x the correct options would be:
    
        variable name
        set name 1
     
         global foo::name
         set name 1
    
         set ::foo::name 1
    
    The first two are the best ones, and offer the best
    performance (variable access about 5x faster than the
    original); I suppose that the second one is backwards
    compatible to tcl7.x, but am not sure. The third option is
    definitely backwards compatible to tcl7.x, but slower in
    tcl8.x (about as fast as the original in general, 3x faster
    in tcl8.5a2).
    
    
  2. login: "msofer"
  3. mimetype: "text/plain"
  4. username: "msofer"