user1934428
user1934428

Reputation: 22225

Bug or feature? Missing closing quote in Tcl is rarely seen as syntactically incorrect.

I tried it with Tcl 8.3 and 8.5: The statement

puts X"

is syntactically correct and outputs just an X and a double quote. I would have expected, that Tcl complains about a missing closing quote. OTOH, if I enter the statements

puts "X

and

puts "

in a tclsh, the statement is not executed yet, but tcls expects me to continue the string in the next line.

Which syntactic rule is hinding behind what looks like an anomaly to me?

Upvotes: 1

Views: 351

Answers (1)

Ignacy Kasperowicz
Ignacy Kasperowicz

Reputation: 421

Do not think it is a bug, as stated in documentation: reference here

[3] Words. Words of a command are separated by white space (except for newlines, which are command separators).

[4] Double quotes. If the first character of a word is double-quote (“"”) then the word is terminated by the next double-quote character. If semi-colons, close brackets, or white space characters (including newlines) appear between the quotes then they are treated as ordinary characters and included in the word. Command substitution, variable substitution, and backslash substitution are performed on the characters between the quotes as described below. The double-quotes are not retained as part of the word.

The key part would be If the first character of a word is double-quote (“"”) then the word is terminated by the next double-quote character.

So in your case if word begins with " than closing double quote is expected, if word does not begins with " than such " is treated as part of the word not as something special as syntax for variables substitution.

Upvotes: 7

Related Questions