Skip to main content

Posts

Showing posts with the label variables

Tcl and OTcl Tutorial For NS2 variables and arrays

Tcl and OTcl Tutorial For NS2 variables and arrays Variables and arrays Defining a variable in Tcl is very simple: set var1 1 set var2 "Tcl Variable 2" The variables can be referenced by prefixing the variable name with a $. For example to print the above variables, we can use puts "var1=$var1, var2=$var2" Any situation in which you require that the value of the variable be used is one in which the $ prefix should be added to the variable name. In some situations, it is necessary to use the variable name directly. For example incr var1 can be used to increment var1. I guess you can think of it as the difference between call-by-reference and call-by-value: in the former case you use the variable name on its own, while in the latter you prefix it with a $. An alternative is to assign the results of a function to a variable. This can be done as follows: set var3 [expr 5*10] This sets the variable var3 to the result of calling the  expr  function with the parameter  5*1...