Version 10 of The major new features of Tcl/Tk 8.6

Updated 2012-11-08 19:07:00 by dgp

[This page is being used to work on building more user-oriented descriptions of the new features of 8.6; please have a bit of care as this is work-in-progress right now]

Included Object Systems

Tcl 8.6 includes two object systems (that's two more than any previous release of Tcl). But just because we provide them does not mean that your scripts have to change; objects in Tcl are just commands that have a particular way of accessing subcommands that you should already be familiar with:

someCommandThatIsAnObject theSubcommandThatIsAMethod someArgument1 someArgument2

If you've used Tk, you've used that pattern. If you've used many of Tcl's commands (the ensembles, like string or namespace or chan or interp), you've used that pattern.

TclOO (also available as a stand-alone package for Tcl 8.5) is designed to be a small, efficient and powerful object system core that is deeply connected into Tcl and into the way that Tcl works logically. It currently does not ship with a substantial class library, but it is designed to offer a base on which other object systems can be built.

[incr Tcl] 4 also ships with Tcl (and it's an example of an object system built on top of TclOO). There's a much larger class library available for itcl.

More on TclOO

More on [incr Tcl]

The Non-Recursive Evaluation Engine

Tcl 8.6 is in many ways a “stackless Tcl”. This has many subtle consequences.

  1. Tcl can now support very deep recursion (though it usually has a limit of 1000 imposed, which you can control with interp recursionlimit).
  2. Tcl can now perform tail-calls, which replace the current procedure call with a call to some other command.
  3. Tcl supports coroutines, a system for allowing you to restructure your programs from continuation-passing style into much more straight-line code (with appropriate yields at the points where you want to stop the coroutine from running while something else is happening).

NRE-enabling of extensions

Errorstack with current parameter values

In addition to the errorInfo, which is written when an error occures, an additional trace, the error stack is generated containing the current parameter values of all called procedures.

Database Support

We now define a standard interface (TDBC) for accessing databases, and ship a few database drivers that support the interface. We also include SQLite, the database engine that started as a Tcl extension and then escaped into the big bad world!

IPv6 Support

Tcl 8.6 is fully IPv6 enabled. As long as your system hostname resolver is configured correctly (sadly, not something that Tcl can do much about if it isn't working right) Tcl's socket will just use the right protocol when connecting to a service.

For server sockets, we now listen on all appropriate protocols. The one observable change is that now when you ask for the local address of a server socket, it can report a list of more than three items. In fact, it will be a list of three items for each protocol supported locally, and you can extract the information easily with foreach:

set s [socket -server someProc 12345]
foreach {address name port} [chan configure $s -sockname] {
    puts "listening on address ${address}, port $port"
}

Note also that hostnames returned when fetching the -sockname and -peername are now usually numeric; support for reverse-DNS is too patchy for the address-to-name translation to be useful in production, unfortunately.

New Commands

lmap and try and zlib and …

The try Command and Error Codes

The new try command exists to make it easier to trap specific problems, rather than the cruder “catch everything, including unexpected problems” that everyone used to use previously. Thus, you can use:

try {
    set f [open $filename w]
} trap {POSIX EACCES} msg {
    puts "Error opening file for writing\n$msg"
}

Without fear of what would happen if you got to that point and something mundane was wrong (e.g., the filename variable being unset).

You can also use the finally clause to try to make it easier to handle doing cleanup:

set f [open $f]
try {
    doStuff with $f
} finally {
    close $f
}

The error codes that you trap with try are lists that go from least specific to most specific. The mechanism has been around in Tcl for a very long time, but has been under-used in previous releases because of the complexity of working with them. The try command changes that. We've also gone through and defined error codes for a great many internally-generated errors (all of which use TCL as the first word of the error code list). If you find any Tcl-generated errors that have their error code still being NONE (and they're not coming from the error or return commands), that's a reportable bug…

Updated msgcat Package

msgcat::mcflset

Facilates to translate your application using message catalog files by not repeating the locale for each translation.

New Tk Features

PNG Image Support for Tk