Version 27 of Magic names

Updated 2016-05-22 00:35:42 by pooryorick

Magic Names are values that have special meaning to the interpreter or a command, and affect the behaviour of those things. It's useful to be aware of them since they don't necessarily occur explicitly in a script, and might therefore be easy to overlook when troubleshooting. For example, $auto_path, whose value might depend on the value of an environment variable, or which might be set somewhere in a script, can lead to not quite the expected packages being loaded.

The tclvars enumerates variable special to the Tcl interpreter. Below are other values to be aware of.

Environment variables

$PATH
May be used by exec.

Variables

Some other magic variable names for Tcl are $args, $argv, and $argv0, as well as the global arrays $env and $tcl_platform.

Values

pkgIndex.tcl
Used by package, via tclPkgUnknown
stdin, stdout, and stderr
Used by open

Canvas tags may be almost any strings - except: all, current, or decimal integers, and substrings like && , !, or || have special meaning.

Literals

.tclshrc
Used by tclsh

Bad magic (taboo names)

When you create a toplevel, do not give it the same name as one any of the script source file names (like a widget), e.g. button.tcl, as is explained in Is there anything I should know before I start coding.

You should not call a procedure "." if it is to run in a wish; it would, on definition, destroy the toplevel window.

DKF: Remember that images are also commands, so calling them things like "open" is a bad idea. Absolutely do not create an image called "." as that causes really bad things to happen. The easiest way to work around this, of course, is to let Tk pick the names for all the images it creates, and for you to store those names in an array indexed by the names that you prefer. Like this, you can be sure you won't hit things unexpectedly. (Also it means that you can use the same "names" to refer to different images in different contexts just by changing the name of the lookup array, which can make programming easier. You could even use read traces to populate the arrays on-demand...

LV: Most Tcl and Tk commands create objects by the name provided by the developer/user, without regard for whether an item by that name already exists. This is as it should be, in most cases, since you don't want to have to use unset before every set, now do you ?