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. (From: [TclHelp]). [[Add discussions about other tcl [#] comment related issues]] If you want to add a line comment, don't forget to end the tcl command first - set stuff [some kind of nonsense] ; # That semi-colon terminates the previous # command, allowing a comment to be added ---- Tcl students frequently ask "[Why can I not place unmatched braces in Tcl comments]?" ---- Tcl comments are almost like null-operation commands. You could write one yourself like this: proc -- args {} -- This is a call to the new proc that does nothing, like a comment -- but this here still does an [exit]!! So it's not like # [exit] [exit] [exit] ... and still won't die ;-) ---- Note the "if 0 ..." [idiom]: if 0 { Any Tcl code to be commented out (with matching braces, of course!) or any other kind of text, will be ignored - and even [exit] won't fire because it's in braces, so left unevaluated! } and a fancy sugar for that: "#" is special only if first character of a command name. Nobody hinders you to write a proc {#} args {} where the braces are only visual markup - the parser strips them off, the proc's name will be just "#". But to call it, you have to escape the "#" sign - with a backslash, or with my favorite sugar: {#} { This is a comment in braces } where the name of the command is pretty self-documenting: "comment in braces"... Much more intuitive than e.g. [Ruby]'s "=begin ... =end", and available with almost zero implementation! ([RS]) In the [Tcl chatroom], [MS] pointed out: "the bytecode compiler recognizes "proc whatever args {}" and compiles no invocation for that; the cost is (almost) nothing. For other empty procs, an invocation will be compiled, so that you have a call/return overhead", and that "if 0 {...}" may raise errors on some contents (up to tcl8.3). Any word corresponding to a bcc'ed command at the start of a line is risky ...: % if 0 {set a b c} % if 0 {if you want to write this, you can't} % if 0 {while you read this, tcl errs out} Therefore, {#} {set any number of words; if you so wish} is more robust than "if 0 {...}", as long as you DO NOT forget the braces, and before 8.4. But {#} do not [[exit]] *will* exit ... ----- [AB] Forgive me for an easy question, but is there a way to comment out a whole block of code in TCL? For instance, I know in C++ you can do so by typing "/*", and then everything that follows is commented out until the compiler comes to "*/". Thanks! Use if {0} { ... code to comment ... } [MG] Tcl doesn't have -real- block-commenting like that, though. The ''if {0} { ... }'' method won't work if you have mismatched braces inside, or anything like that - the first mismatched ''}'' will end the ''if'', and the code after it will start running. (noname) 18-Aug-05 Try it! Use # First, define an block comment procedure, as: proc /* {args} {} # Then,you can use it as: /* { ... .. any comments,(with carefull { } pairs). } and more args in this line will be ignored. Well, technically, isn't there also problems with /* in C++? At least in C, you can add a like of /* to start a block comment, but if the code being commented already has a /* */ in it, the ending */ of the included comment stops the block comment as well. I see that as functionally similar to the if {0} { ... } situation ... ---- [RS] 2006-07-13: In the [Tcl chatroom] someone asked how to have comments in [list]s. First answer is, lists are data, and comments apply only where commands are parsed; but the second answer is: of course! Lists in a source file come as strings (often in {} braces), and that Tcl is good at doing things with strings is well-known :^) One [regsub] is enough to strip substrings between # and the next newline: set data { # This is an example of comments in data test { 4711 # an integer all # a word } date today # one more test } % regsub -all {#.*?\n} $data \n test { 4711 all } date today [RLH] Wouldn't it be nifty: #- Everything in here is a comment or something similiar. #- ---- [SDW] 2007-03-14: In the [Tcl chatroom] I also shared one of my styles, which is to wrote comments into dummy variables. While they do take up memory, and are not cleaned up by the compiler like the if 0 {...} comments are, well you don't have to worry about future changes in the compiler barfing up syntax errors. I'm paranoid, largely because I have code that's been kicking around since (gasp) Tcl 8.0beta. set comment { And now I can put on comments to by heart's content. Without fear of the whitespace getting munched. Nor even that the my "quotes" will leak out of the brackets } Back to the proc -- args {} idom. If you are concerned about the comment being evaluated, enclose it in curly brackets: proc -- args {} -- { And now I can put on comments to by heart's content. Without fear of the whitespace getting munched. Nor even that the my "quotes" will leak out of the brackets and now even [exit] will not be evaluated. } ---- Also note there is special syntax for adding comments to the extended regular expressions supported in Tcl. ---- [Tcl syntax help] - [Arts and crafts of Tcl-Tk programming] - [Category Control Structure]