Forum OpenACS Q&A: Response to "good" tcl code

Collapse
Posted by Michael A. Cleverly on
What idiot added empty_string_p? That's from Philip's original utilities.tcl file... :^)

And, actually, you don't want to do {$string == ""} because that can blow up if you have something that looks like it could be an integer (12345678901234567890) that can't be represented as a 32 bit integer, OR, something that looks like an Octal number, but isn't: 08 (for August), for example. Much better (in Tcl 8.3) to use [string equal]. Tcl 8.4a3 has {$string eq ""} ...

Namespaces, advanced regular expressions, ability to handle binary data, and Unicode support are the biggies. Other new things:

  • string map can replace (multiple) regsub's more efficiently in many cases
  • foreach can take a list of variables (instead of a single variable). Thus, instead of:
    set foo [lindex $args 0]
    set bar [lindex $args 1]
    set baz [lindex $args 2]
    you can employ:
    foreach {foo bar baz} $args break
  • You can find a pretty detailed list of changes between Tcl versions at http://mini.net/tcl/2.html?changes.