Skip to content
Tcl Source Code History Of Ticket 98217d03e0c0032a
Login

History Of Ticket 98217d03e0c0032a

Artifacts Associated With Ticket 98217d03e0c0032a

  1. Ticket change [f47cd01c96] (rid 141626) by anonymous on 2015-04-25 16:56:27:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/plain"
    4. comment initialized to:
      Imagine this situation:
         You have a nested namespace with a lot defined constants. You want to import all these constants or some of them, because you don't want to write constantly the long namespace path to these constants.
      
      The command "namespace import" can only import procedures. But it can't import variables. My proposal is to add an option to "namespace import", for example "namespace import -variable", for importing variables of another namespace.
      
    5. foundin initialized to: "8.6"
    6. is_private initialized to: "0"
    7. login: "anonymous"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "1c4b6cdb98c9dfc4d1e74018f3f4efa00ad217e2"
    10. resolution initialized to: "None"
    11. severity initialized to: "Minor"
    12. status initialized to: "Open"
    13. submitter initialized to: "anonymous"
    14. subsystem initialized to: "- New Builtin Commands"
    15. title initialized to:
      Add option to "namespace import" command for importing also variables
      
    16. type initialized to: "Bug"
  2. Ticket change [87d46a9b91] (rid 141627) by msofer on 2015-04-25 17:10:16:

    1. assignee changed to: "msofer"
    2. icomment:
      I believe "namespace upvar" does most if not all of what you want. See [http://tcl.tk/man/tcl8.6/TclCmd/namespace.htm#M21]
      
    3. login: "msofer"
    4. mimetype: "text/x-fossil-wiki"
    5. status changed to: "Pending"
  3. Ticket change [23bdec5294] (rid 141628) by anonymous on 2015-04-25 20:41:08:

    1. icomment:
      Hi Miguel,
      
      now I am using the next trick. But don't you think that it's more concise something like this "namespace import -variable moduleA::moduleB::moduleC::moduleD::constants"?
      
      This is the trick:
      
      proc import_constants {path_to_constants variable_name args } {
          upvar $variable_name _variable_name
          upvar $path_to_constants _path_to_constants
          
          if { [llength $args] > 0} {
      
      	foreach arg $args {
                  set _variable_name($arg)  [dict get $_path_to_constants $arg]
      	}
          } else {
                  array set _variable_name $_path_to_constants
          }
      }
      
      
      namespace eval moduleA::moduleB::moduleC::moduleD {		
          variable constants [ dict create {*}{ 
      		constant1 value1
      		constant2 value2
      		constant3 value3
      	}]
      }
      
      import_constants moduleA::moduleB::moduleC::moduleD::constants constants
      
      puts $constants(constant1)
      
    2. login: "anonymous"
    3. mimetype: "text/plain"
  4. Ticket change [17bb03e5e2] (rid 141629) by anonymous on 2015-04-25 20:54:44:

    1. icomment:
      It's true. "namespace upvar" is all that I need.
      
      namespace eval moduleA::moduleB::moduleC::moduleD {		
          variable constants  { 
      		constant1 value1
      		constant2 value2
      		constant3 value3
      	}
      }
      
      namespace upvar ::moduleA::moduleB::moduleC::moduleD constants constants_str
      array set constants $constants_str
      puts $constants(constant1)
      
    2. login: "anonymous"
    3. mimetype: "text/plain"
  5. Ticket change [ac3a015ead] (rid 141630) by msofer on 2015-04-25 21:06:19:

    1. closedate changed to: "2457138.37939314"
    2. closer changed to: "msofer"
    3. icomment: "Great! Closing the ticket then."
    4. login: "msofer"
    5. mimetype: "text/plain"
    6. status changed to: "Closed"