TCL command language interface

The macro language implemented in the SICS server is John Ousterhout's[1] Tool Command Language (TCL)[2]. Tcl has control constructs, variables of its own, loop constructs, associative arrays and procedures. Tcl is well documented by several books[3], online tutorials and manuals [4]. For getting further informations on Tcl have a look on the TCL WWW Info[5] of Tcl Web server[6]. All SICS commands are available in the macro language. Some potentially harmful Tcl commands have been deleted from the standard Tcl interpreter. These are: exec, source, puts, vwait, exit, gets and socket. Below only a small subset of the most important Tcl commands like assigning variables, evaluating expressions, control and loop constructs are described. For complete description of Tcl command have a look on the manual[7] pages or on one of the many books about Tcl/Tk.

set - Read and Write variables

Synopsis. set varName ?value?

Description. Returns the value of variable varName. If value is specified, then set the value of varName to value, creating a new variable if one doesn't already exist, and return its value. If varName contains an open parenthesis and ends with a close parenthesis, then it refers to an array element: the characters before the first open parenthesis are the name of the array, and the characters between the parentheses are the index within the array. Otherwise varName refers to a scalar variable.

expr - Evaluate an expression

Synopsis. expr arg ?arg arg ...?

Description. Concatenates arg's (adding separator spaces between them), evaluates the result as a Tcl expression, and returns the value. The operators permitted in Tcl expressions are a subset of the operators permitted in C expressions, and they have the same meaning and precedence as the corresponding C operators. Expressions almost always yield numeric results (integer or floating-point values). For example, the expression

expr 8.2 + 6

evaluates to 14.2. Tcl expressions differ from C expressions in the way that operands are specified. Also, Tcl expressions support non-numeric operands and string comparisons. For some examples of simple expressions, suppose the variable a has the value 3 and the variable b has the value 6. Then the command on the left side of each of the lines below will produce the value on the right side of the line:

expr 3.1 + $a 6.1
expr 2 + "$a.$b" 5.6
expr 4*[llength "6 2"] 8
expr {{word one} < "word $a"} 0

Math functions. Tcl supports the following mathematical functions in expressions:

acos cos hypot sinh
asin cosh log sqrt
atan exp log10 tan
atan2 floor pow tanh
ceil fmod sin

Each of these functions invokes the math library function of the same name; see the manual entries for the library functions for details on what they do. Tcl also implements the following functions for conversion between integers and floating-point numbers and the generation of random numbers:

abs(arg), double(arg), int(arg), rand(), round(arg), srand(arg).

if - Execute scripts conditionally

Synopsis. if expr1 ?then? body1 elseif expr2 ?then? body2 elseif ... ?else? ?bodyN?

Description. The if command evaluates expr1 as an expression (in the same way that expr evaluates its argument). The value of the expression must be a boolean (a numeric value, where 0 is false and anything is true, or a string value such as "true" or "yes" for true and "false" or "no" for false); if it is true then body1 is executed by passing it to the Tcl interpreter. Otherwise expr2 is evaluated as an expression and if it is true then body2 is executed, and so on. If none of the expressions evaluates to true then bodyN is executed. The then and else arguments are optional "noise words" to make the command easier to read. There may be any number of elseif clauses, including zero. BodyN may also be omitted as long as else is omitted too. The return value from the command is the result of the body script that was executed, or an empty string if none of the expressions was non-zero and there was no bodyN.

for - "For" loop

Synopsis. for start test next body

Description. For is a looping command, similar in structure to the C for statement. The start, next, and body arguments must be Tcl command strings, and test is an expression string. If a continue command is invoked within body then any remaining commands in the current execution of body are skipped; processing continues by invoking the Tcl interpreter on next, then evaluating test, and so on. If a break command is invoked within body or next, then the for command will return immediately. The operation of break and continue are similar to the corresponding statements in C. For returns an empty string.


						
for {set x 0} {$x<10} {incr x} {
     puts "x is $x" 
}

					

while - Execute script repeatedly as long as a condition is met

Synopsis. while test body

Description. The while command evaluates test as an expression (in the same way that expr evaluates its argument). The value of the expression must be a proper boolean value; if it is a true value then body is executed by passing it to the Tcl interpreter. Once body has been executed then test is evaluated again, and the process repeats until eventually test evaluates to a false boolean value. Continue commands may be executed inside body to terminate the current iteration of the loop, and break commands may be executed inside body to cause immediate termination of the while command. The while command always returns an empty string.


						
set x 0 
while {$x<10} { 
     puts "x is $x" 
     incr x 
} 

				
					

Notes

[1]

http://cseng.awl.com/authordetail.qry?AuthorID=69

[2]

http://www.tcltk.com

[3]

http://www.cica.indiana.edu/cica/faq/tcl/tcl.html

[4]

http://www.scriptics.com/man/tcl8.0/contents.htm

[5]

http://www.sco.com/Technology/tcl/Tcl.html

[6]

http://www.tcltk.com

[7]

http://www.scriptics.com/man/tcl8.0/contents.htm