**Assigning values to variables** !!!!!! '''Previous lesson''' | '''Index''' | '''Next lesson''' !!!!!! In Tcl, everything may be represented as a string, although internally it may be represented as a list, integer, double, or other type, in order to make the language fast. The assignment command in Tcl is `set`. When `set` is called with two arguments, as in: ====== set fruit Cauliflower ====== it places the second argument (`Cauliflower`) in the memory space referenced by the first argument (`fruit`). `Set` always returns the contents of the variable named in the first argument. Thus, when `set` is called with two arguments, it places the second argument in the memory space referenced by the first argument and then returns the second argument. In the above example, for instance, it would return "Cauliflower", without the quotes. The first argument to a `set` command can be either a single word, like `fruit` or `pi` , or it can be a member of an array. Arrays will be discussed in greater detail later, for the time being just remember that many data can be collected under a single variable name, and an individual datum can be accessed by its index within that array. Indexing into an array in Tcl is handled by putting the index within parentheses after the name of the variable. `Set` can also be invoked with only one argument. When called with just one argument, it will return the contents of that argument. Here's a summary of the `set` command.
set
varName
?value?
value
is specified, then the
contents of the variable varName
are
set equal to value
.
varName
consists only of
alphanumeric characters, and no parentheses, it is a scalar
variable.
varName
has the form varName(index)
, it is a member of an
associative array.