Evaluating something starting with a # fails to treat it as a comment
Closed / Invalid1e95cbaf89ad0e0d48aa374d7ad0515ea2c2b862Created 13 years agoUpdated 13 years ago
Descriptionplain2014-04-04 04:30:01
So I decided to stop living in the past and upgraded from Tcl 8.4 to 8.6. And got bitten by something that used to work just fine:
First, the expected behavior:
tclsh8.6
% set tcl_patchLevel
8.6.1
% set comment "#fubar snafu"
#fubar snafu
% lindex $comment 0
#fubar
% eval $comment
%
Now the same thing with a list. Note that in Tcl 8.4, the commands below worked identically to the above. Not so in 8.6:
% set comment [list #fubar snafu]
{#fubar} snafu
% lindex $comment 0
#fubar
% eval $comment
invalid command name "#fubar"
Looks like a bug in parsing. The first word of the list is unquestionably this:
#fubar
This is clear from the result of 'lindex' and from the language rules (http://www.tcl.tk/man/tcl8.6/TclCmd/Tcl.htm):
"If the first character of a word is an open brace (“{”) and rule [5] does not apply ... The word will consist of exactly the characters between the outer braces, not including the braces themselves"
and
"If a hash character (“#”) appears at a point where Tcl is expecting the first character of the first word of a command, then the hash character and the characters that follow it, up through the next newline, are treated as a comment and ignored. The comment character only has significance when it appears at the beginning of a command."
Well, I do have # in first character of the first word of the command. Why is Tcl8.6 not treating it as a comment???
While I don't have a newline in here, newlines are separators and I have one command to evaluate, so separator presence is moot. But let's add it:
% eval "$comment\n"
invalid command name "#fubar"
Still not good.
Looks like a clear bug to me.
jan.nijtmanswiki2014-04-04 12:42:22
Well, the string you are evaluation doesn't start with "#" any more, it starts with "{". The reason for this change is explained here:
http://www.tcl.tk/cgi-bin/tct/tip/148
In short: Your script was depending on a Bug in Tcl 8.4, which was fixed in Tcl 8.5. Sorry ......
jan.nijtmans Ticket [1e95cbaf89]: 4 changes
[History diff]2014-04-04 12:46:14
Grumpy Coderplain2014-05-30 19:04:01
The documentation clearly states that the parsed word does not include the braces, and that whether something is a comment or not depends on the first character of the WORD, and not the first character of the STRING containing that word. If the current behavior is deemed desirable, then the documentation of the language should be fixed so that it is consistent with the behavior.
dgpplain2014-05-30 19:33:09
You say "current behavior" as if it were something novel, and not the Tcl bug-fixed reality for more than 10 years. The change that was made in 2003 was made to make Tcl behave as documented. Tcl was buggy on this point. Current releases now are not. This is all spelled out in TIP 148. Tcl 8.4 was left buggy just to offer folks the option to adjust at their leisure. A 10 year grace period is far from unreasonable. Stay with 8.4 if you cannot accept it.
dkfwiki2014-06-03 08:35:39
See [489537] for more information.
Log in (anonymous is fine) to add a comment.