2

I am trying to use the Tcl dict data structure:

http://www.tcl.tk/man/tcl/TclCmd/dict.htm

But when I try to run my script, the script displays the following error:

invalid command name "dict"

I believe it is caused by my not including any Tcl packages. Which package(s) should I require to use Tcl dict?

Thanks

czchlong
  • 2,434
  • 10
  • 51
  • 65

3 Answers3

7

Either use Tcl 8.5 (put package require Tcl 8.5 at the top of your scripts to make them fail fast) or use the third-party dict package for Tcl 8.4 (by adding a package require dict), which is based off large parts of the dict implementation in 8.5.

The dict package isn't as fast as the code in 8.5 (as it lacks support from Tcl's bytecode engine) and IIRC doesn't do enforced order maintenance either. I'd really recommend upgrading to Tcl 8.5 instead, if you can. (For one thing, 8.4 is near the end of its extended support lifecycle.)

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
  • 1
    Also, if you're using Tcl 8.3 or before then **upgrade now.** _Please!_ The `dict` command is not supported at all in versions that old (and the scripts to present a similar interface are desperately slow). – Donal Fellows Dec 27 '12 at 21:02
3

package require Tcl 8.5. The dict command was added in 8.5. Adding a line like this will ensure your script states its version requirement up front.

patthoyts
  • 32,320
  • 3
  • 62
  • 93
1

If you are using Active state TCL kit use "teacup install dict" command to load dict package from active state lib.

user16691
  • 35
  • 3