Skip to content
Tcl Source Code History Of Ticket 959147ffffffffff
Login

History Of Ticket 959147ffffffffff

Artifacts Associated With Ticket 959147ffffffffff

  1. Ticket change [36a6d6a787] (rid 107146) by msofer on 2004-05-23 23:28:31:

    1. assignee initialized to: "msofer"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      There is a fundamental problem with varName resolution
      in namespaces. The variable lookup is as follows: 
      (1) lookup in the current namespace; if the var exists,
      return a ref
      (2) lookup in the global namespace; if the var exists,
      return a ref
      (3) if the var has to be created, create it in the
      local namespace
      
      Quite apart from the difficulty of defining what it
      means for a variable to exist (see Bug #959052), this
      behaviour is surprising and dangerous. 
      
      A simple variable call may refer to a ns-local or
      global variable, under circumstances that are difficult
      to check, and which may vary depending on non-local issues.
      
      namespace.n defines the rule as: 
      "Command and variable names are always resolved by
      looking first in the current namespace, and then in the
      global namespace. Namespace names, on the other hand,
      are always resolved by looking in only the current
      namespace."
      
      That the process for variables is black magic is
      actually implicit in that man page: "You can use the
      namespace which command to clear up any question about
      name resolution." But there is no hint of the fragility
      of the procedure with respect to the existence of the
      global variable, especially for "creative writing" -
      ie, creating a variable and setting its value at the
      same time.
      
      Note that commands do not have this creative writing
      problem: [proc] always creates the command in the
      current namespace if the name is unqualified.
      
      This RFE proposes that we simplify the varName
      resolution rule in namespaces so that it is always
      simple and predictable, just as it is for varName
      resolution in proc bodies. The new description would be:
      
      "Command names are always resolved by looking first in
      the current namespace, and then in the global
      namespace. Namespace and variable names, on the other
      hand, are always resolved by looking in only the
      current namespace."
      
      
      
      
      
      
      
    4. foundin initialized to: "None"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "msofer"
    9. subsystem initialized to: "07. Variables"
    10. title initialized to: "Restore sanity to variable name resolution"
    11. type initialized to: "RFE"
  2. Ticket change [28a2cf7e3f] (rid 88733) by msofer on 2006-09-30 00:51:16:

    1. priority changed to: "8"
  3. Ticket change [5de805bca6] (rid 140083) by msofer on 2014-09-29 00:26:36:

    1. closer changed to: "nobody"
    2. comment changed to:
      There is a fundamental problem with varName resolution
      in namespaces. The variable lookup is as follows: 
      (1) lookup in the current namespace; if the var exists,
      return a ref
      (2) lookup in the global namespace; if the var exists,
      return a ref
      (3) if the var has to be created, create it in the
      local namespace
      
      Quite apart from the difficulty of defining what it
      means for a variable to exist (see Bug #959052), this
      behaviour is surprising and dangerous. 
      
      A simple variable call may refer to a ns-local or
      global variable, under circumstances that are difficult
      to check, and which may vary depending on non-local issues.
      
      namespace.n defines the rule as: 
      "Command and variable names are always resolved by
      looking first in the current namespace, and then in the
      global namespace. Namespace names, on the other hand,
      are always resolved by looking in only the current
      namespace."
      
      That the process for variables is black magic is
      actually implicit in that man page: "You can use the
      namespace which command to clear up any question about
      name resolution." But there is no hint of the fragility
      of the procedure with respect to the existence of the
      global variable, especially for "creative writing" -
      ie, creating a variable and setting its value at the
      same time.
      
      Note that commands do not have this creative writing
      problem: [proc] always creates the command in the
      current namespace if the name is unqualified.
      
      This RFE proposes that we simplify the varName
      resolution rule in namespaces so that it is always
      simple and predictable, just as it is for varName
      resolution in proc bodies. The new description would be:
      
      "Command names are always resolved by looking first in
      the current namespace, and then in the global
      namespace. Namespace and variable names, on the other
      hand, are always resolved by looking in only the
      current namespace."
      
    3. icomment:
      To illustrate the problem, consider:
      
      % set a 0
      0
      % namespace eval x {set a 1; set b 1}
      1
      % set a
      1
      % set b
      can't read "b": no such variable
      % set x::a
      can't read "x::a": no such variable
      % set x::b
      1
      
    4. login: "msofer"
    5. mimetype: "text/plain"
    6. severity changed to: "Minor"
  4. Ticket change [f13002d65b] (rid 140084) by ferrieux on 2014-09-29 07:31:15:

    1. icomment:
      +1 for this RFE, of course, as (unfortunately only a tiny) part of the Augean Stables lying ahead.
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
  5. Ticket change [fb487ca184] (rid 140113) by aku on 2014-09-29 15:07:13:

    1. icomment:
      IIRC this describes the "creative writing"-problem with var resolution, with the missing namespace var unexpectedly created in the global namespace.
      
      Yes, this should be fixed.
      
    2. login: "aku"
    3. mimetype: "text/plain"
  6. Ticket change [91724be600] (rid 148013) by dkf on 2016-07-14 07:11:29:

    1. assignee changed to: "aku"
    2. icomment:
      This was even hitting <tt>namespace upvar</tt> until recently, but I changed that so that at least that command locates variables without resolvers involved. (That also technically touches the behaviour of <tt>global</tt>, but that was the case where the existing code mostly worked.)
      
    3. login: "dkf"
    4. mimetype: "text/x-fossil-wiki"
  7. Ticket change [c78b20a48d] (rid 261553) by serhiy.storchaka on 2026-11-13 11:18:45:

    1. closedate changed to: "2461357.9713335303"
    2. closer changed to: "serhiy.storchaka"
    3. icomment:
      Implemented by TIP 278 in Tcl 9.0: unqualified variable names in a namespace are resolved only in the current namespace, so the example above now sets x::a and leaves ::a alone.
      
    4. login: "serhiy.storchaka"
    5. mimetype: "text/x-fossil-wiki"
    6. resolution changed to: "Fixed"
    7. status changed to: "Closed"