proc source {filename} { set f [open $filename] set script [read $f] close $f # Only this next line is not done by normal [source] regsub -all {/\*.*?\*/} $script {} script set saveScriptname [info script] info script $filename uplevel 1 $script info script $saveScriptname }UKo 2007-05-10: for nested scripts it is necessary to reset the scriptname that was in use before!DKF: No it's not, since that information should actually be just restored automatically on return from your procedure.With this, you could then use C-style comments in the rest of your code, like this:
foreach argument $argv { /* process the command line */ /* print it */ puts $argument /* print its length */ puts [string length $argument] /* if {$argument == 0} { Unbalanced braces in comments! */ frobnicate /* comment in the middle */ $argument /* } */ }OK, so I've gone a little mad with commenting there. :-) But the point is, once you've done that redefinition, all scripts loaded in that interpreter will understand your new (local) commenting rules. Please don't distribute the files with those changes in though, or you'll have people scratching their heads a lot when doing maintenance. :-D
But, of course, the following might not work as expected (depending on what you expect...):
set pityTheFool { /* who wants to treat a comment as data */ }KPV I've always felt that languages, such as HTML and postscript, where changing the content of a comment can affect the output to be rather horrid.DKF: Yeah, but that's the trade-off with doing this sort of thing. I suppose a more complex rule for defining what is a comment and what is not could be defined, but that'd be hairy (and much longer to write).
For other comment styles, see also:
- tcllib docstrip module [1] - docstrip and tclldoc