Tcl -- variable

来源:互联网 发布:淘宝店铺释放后保证金 编辑:程序博客网 时间:2024/06/07 06:34

1. variable - create and initialize a namespace variable

    用于在名字空间里创建和初始化变量。

2. 语法

    variable ?name value...? name ?value?

3. 说明

    This command is normally used within a namespace eval command to create one or more variables within a namespace.

    Each variable name isinitialized with value. The value for thelast variable is optional. 最后一个变量的值是可选的。

   If a variable name does not exist, it is created. In this case, if value is specified, it is assigned to the newly created variable.

   如果变量名不存在,则创建该变量。如果指定了value,则将该value赋值给variable.

   If no value is specified, the new variable is left undefined. 如果没有指定value,可以在后续进行定义。

   If the variable already exists, it is set to value if value is specified or left unchanged if no value is given.

   如果变量已经存在,如果有value,则将更改它的值为value值。如果没有value,则它之前的值保持不变。

   If name includes any namespace qualifiers(其他名字空间的限定符), the variable is created in the specified namespace.

   If the variable is not defined, it will be visible to the namespace which command, but not to the info exists command.

   A name argument cannot reference an element within an array.

  (不应该用数组元素,而应该用数组名,随后用set或者array命令来定义该数组)

   Instead, name should reference the entire array, and the initialization value should be left off. (初始值先不管)

   After the variable has been declared, elements within the array can be set using ordinary set or array commands.

4. 举例

   1) 定义一个名字空间some,里面有一个数组day

   

   2) 定义一个名字空间lion,里面有一个proc为fun,引用::some::day(some名字空间中的day数组)

  

   3) 调用lion名字空间中的fun

  

0 0
原创粉丝点击