tags:

views:

110

answers:

2

I have code here

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 put the whole procedure into a single comment, i don't want put each line with #, is there any possibility like in java /* .. */ with all code commented, like that in tcl. and i also want some of the text will be put single comment

+6  A: 

This question is unclear. Do you mean to comment out a block of code? Well there are two ways: prefix every line with # use something along

if { 0 } {
    a section
    of
    "commented" code
}

If not please rephrase this question of show us an example on what you mean.

Friedrich
To be clear, Tcl does not parse the body *at all* in the case where it works out that it can never be executed (other than to check for curly brace balancing).
Donal Fellows
@Friedrich: it needs to be mentioned that the 'if 0' trick won't work if the lines of code to be blocked out have unbalanced braces.
Bryan Oakley
+5  A: 

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} ...

slebetman
of course, this won't work if the stuff you are commenting out is buggy and has unbalanced braces.
Bryan Oakley