Tcl Cheatsheet -------------- Substitutions: - variable - command - backslash Quoting - backslashes ignore next char - double quotes ignore whitespace and semicolon - braces ignore everything except line continuation Comments - command (not word!) starts with `#' Variables - set n 123 - set n evaluates the value - unset n - incr n ?arg? increments n by one or arg - append s foo efficient operation: does not copy strings! - set a(first) val arrays are associative - $n value of n - $a(first) value of element `first' in `a' - ${n}m value of n followed by letter m - argv0 argv argc predefined variables Expressions - expr ... concats all args and evaluations them - operators like in ANSI C - math functions similar to C in function syntax (!) Lists - list ?val val ...? creates list of arguments - concat ?list list ...? creates list of argument's contents - lappend varname val ?val ...? - linsert list index val ?val ...? - lreplace list first last ?val ...? - lindex list index 0-based - lrange list first last bounds inclusive; special val `end' - lsearch list pattern -glob -exact -regexp - llength list - lsort list -ascii -integer -real -command cmd -increasing -decreasing - split string delimiter - join list ?delimiter? default delimiter is a space Control flow - if {expr} { ... } elseif {expr} { ... } else { ... } - switch {string} { -glob -exact -regexp pattern {...} ... } - while {expr} { ... } - for {stmt} {expr} {stmt} { ... } - foreach i list { ... } - break - continue - source filename - eval arg ... another level of evaluation Procedures - proc name arglist { ... } - return ?val? - global var ... local reference to global var - upvar - uplevel ... to be continued ...