Version 3 of What kinds of variable names can be used in Tcl

Updated 2002-01-17 16:34:51

Purpose: discuss what all is known about Tcl variable names - what are the limits, tricks, and tips?


LV: I've seen people show examples of Tcl variable names from 0 characters long to quite long (more than 30 I believe). The names can contain spaces and many other special characters. I would, myself, avoid the use of metacharacters such as [ ] , ( ) $ : { } and probably a few others, just to save myself the quoting nightmare that one might encounter.

I also believe that some extensions impose additional 'restrictions' - for instance, I believe that Tk generally expects widget names to begin with a period and not to use an upper case alpha as the first character.

RS says:

As far as I'm aware, a variable name may be any string, from the empty string up. (Well, sequences of semicolons have special meaning, so they may not be arbitrarily thrown in). The $ parser restricts variable names to A-Za-z0-9_, so it's wise to stay in that range (otherwise you might have to brace (which prevents Unicode expansion... or set \u20AC if you have a variable names with the Euro sign.

de: I can do 'set � foo; puts $�' (this � is adiaresis, if you only see a strange char). What do you mean with "The $parser restricts variable names to A-Za-z0-9_?

suchenwi: I've heard there was a bug report so "national" letters would also be allowed by the $ parser... so it seems this has been fixed. Which version?

suchenwi: In 8.2.3, "�" is not taken by the $ parser. de:8.3.2