4 ms·
# [set x 3] set x can't read "x": no such variable # puts hello --nothing happens-- What are you talking about?
by pmarin 18y ago
# [set x 3]
set x
can't read "x": no such variable
# puts hello
--nothing happens--
What are you talking about?
- kragen 18y agoCompare the behavior of # to the behavior of puts. If you puts [set x 3], not only does it print out 3, it also sets x to 3. If you # [set x 3], it does not set x to 3, because # is not actually a command that ignores its arguments; it is a comment, just like in Python, Perl, or sh. Similarly, if # were a command, a semicolon would terminate it and start a new command, but it doesn't. The comment continues to the end of the line.
- gaius 18y agoIf # were a comment character in the language you could do this: % puts "hello" # hello bad argument "hello": should be "nonewline" But this works: % puts "hello" ;# hello hello That's the point; that nothing in Tcl is "special" or "reserved", everything is a command that takes parameters.
- kragen 18y agoI didn't remember that you can't have a comment inside of a statement, but you're still wrong! It's true that you can't have comments in as many contexts in Tcl as you can in most languages, but it is not true that they are just ordinary statements; ordinary statements evaluate their arguments. "#" comments don't evaluate their "arguments", don't terminate at semicolons, and you can't redefine the meaning of "#" with "proc", so "#" is special and reserved — just in fewer contexts than in other languages that use it as a comment character.