tclcommentsstring-literals

How do I comment out a code block in Tcl?


Considering the following code

proc checkPrime {no} { 
    set i 1 
    set count 0 
    while {$i < $no} { 
        if {{$no%$i} eq 0} {
            incr count 
        } 
        if {$count eq 2} { 
            puts "the number is prime number" 
            return 
        }
        incr i 
    } 
} 

I want to put the whole procedure into a single comment, I don't want to have to put # before each line.

Is there any possibility to comment multiple lines in Tcl, as there is in Java using /* .. */?

I also would like to comment out part of the text. Is that possible?


Solution

  • Apart from the if {0} .. which is idiomatic (and one that most tcl programmers recognize) you can also use any other construct and stuff the things you want commented out in brace quotes. The real mechanism preventing execution here is that things inside brace quotes don't get substituted.

    Here are some of my favourites. I like them because they are self-documenting:

    set COMMENTED_OUT {
    
       commented out stuff
    
    }
    

    and

    proc COMMENTED_OUT {} {
    
        commented out stuff
    
    }
    

    I tend to prefer the proc because the block of commented out text is really a block of code.

    Note that tcl does not compile proc bodies until first execution so commenting out using a proc is as cheap as set and if {0} ...