Funny Variable Names; The Unset Command - Newport XPS-Q8 Manual

Universal high-performance motion controller/driver
Table of Contents

Advertisement

XPS-Q8
EDH0307En1041 — 10/17
⇒ var
set
name
⇒ var
set
$name
⇒ the value of var
This is a somewhat tricky example. In the last command, $name gets substituted with
var. Then, the
set
var. Nested
The last set command above can be written as follows:
set [set
name]
⇒ the value of var
Using a variable to store the name of another variable may seem overly complex,
however, there are situations when it is very useful. There is even a special command,
upvar, that makes this sort of trick easier.
2.2.9.1

Funny Variable Names

The Tcl interpreter makes some assumptions about variable names that makes it easy to
embed variable references into other strings. By default, it will assume variable names
contain only letters, digits, and the underscore. The construct $foo.o represents a
concatenation of the value of foo and the literal ".o".
If the variable reference is not delimited by punctuation or white space, then you can
use curly braces to explicitly delimit the variable name (e.g., ${x}). You can also use
this to reference variables with funny characters in their name, although generally the
use of funny variable names is not ideal. If you find yourself using funny variable
names, or computing the names of variables, then you may want to use the
command.
Example 1–16: Embedded variable references.
set
foo filename
set
object $foo.o
⇒ filename.o
set
a AAA
set
b abc${a}def
⇒ abcAAAdef
set
.o yuk!
set
x ${.o}y
⇒ yuk!y
2.2.9.2

The unset Command

You can delete a variable with the
unset
varName varName2 ...
Any number of variable names can be passed to the
unset
will raise an error if a variable is not already defined.
set
command returns the value of var, which is the value of
commands provide another way to achieve a level of indirection.
unset
10
command:
unset
command. However,
Tcl Manual
upvar

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents