Any way to insert a comment into a Tcl command?

I would like to have a comment inside the command, and this seems impossible, given that the "#" character is defined in Tcl 8.4 as follows:

If a hash character (`` # '') appears at the point where Tcl expects the first character of the first word of the command, then the hash character and subsequent characters passing through the next new line are considered as comments and are ignored. The comment symbol only matters when it appears at the beginning of the command.

Imagine an example of how this might work (none of these comments worked in my experiments):

array set myArray [list red 3        \
                        blue 4       ;# Blue is before purple.
                        purple 5     # Purple is after red.
                        green 7      \
                        yellow 8]

It seems the tricky part is how to continue the list command with inline comment? Perhaps something like the C ++ style in the / * Embedded comment. * /, but I see only #, which is used in Tcl for comments to the end of the line, nothing for the syntax of the beginning and end of the comment.

+3
source share
1 answer

No, you cannot embed a comment in a command invocation. Comments in Tcl do not quite work the same as in other languages. Some people stumble over this; most experienced Tcl programmers don't give him a second thought.

The rare times that you really need to make, you can usually bypass easily. Using your example:

set myArray(red) 3
set myArray(blue) 4 ;# Blue is before purple
set myArray(purple) 5 ;# Purple is after red
set myArray(green) 7
set myArray(yellow) 8

, , , , , , .

+6

Source: https://habr.com/ru/post/1718390/


All Articles