## Tcl Cheat Sheet

the gist

home
programming
 variables `\$a` `set a {a string}` `global a` Use a global variable within a procedure. comments `# a comment` `set a \$b ;# not much to say about this` generic expression `\$a ? \$b : \$c` arithmetic Basic arithmetic uses the `expr` command. `expr 44*4` strings `{what ever}` `\$a\$b` concatenation `string length \$a` `string compare \$a \$b` returns 1, 0, or -1. numbers `\$a + \$b` `\$a - \$b` `- \$a` `\$a * \$b` `\$a / \$b` `abs(\$a)` `exp(\$a)` `pow(\$base,\$exp)` `sin(\$a)` [etc.] lists `list \$elem1 \$elem2` `concat \$list1 \$list2` `lappend listvarname \$newelem` `lindex \$list \$n` nth element `llength \$list` `concat \$list1 \$list2` functions ``` [foo 1 {a b c}] ``` ```proc foo {x y} { action1 action2 return ... \$x ... } ``` sentences `0` false Anything but `0` is taken as true. `\$a == \$b` numeric `\$a != \$b` numeric `\$a != \$b` numeric `\$a < \$b` numeric `\$a <= \$b` numeric `\$a >= \$b` numeric `\$a > \$b` numeric `\$a && \$b` logical `\$a || \$b` logical `! \$a` logical actions `set a 44` `foo 1 {a b c}` `proc` is an action. ```if {\$s} { action1 } elseif {\$t} { action2 } else { action3 } while {\$s} { action } foreach user \$users { action } ```
home
programming

the gist

Support open standards!