Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Switch statement case fails when using a open parenthesis in a comment

Closed / Invalid3a24cc9df1619a130120e8cef8560aef0561c1f0Created 2 years agoUpdated 2 years ago
Descriptionplain2025-04-12 22:42:59
Example code:

proc yay {lang} {
    switch $lang { 
        tcl { 
	    puts "Yay! TCL"
            # having this { will break this case now
        }
    }
} ;# end proc

I then have to apply an additional { to the get the syntax to execute but results with invalid command name "}"

% yay "tcl"
Yay! TCL
invalid command name "}"

Not sure feature, or bug; so feel free to close. 

Surely a comment is a comment and shouldn't be executed? If recall correctly it's down to that switch cases are executed as lists. FWIW.
mookie Ticket [3a24cc9df1]: 3 changes [History diff]2025-04-12 22:43:40
mookie Ticket [3a24cc9df1]: 3 changes [History diff]2025-04-12 22:44:41
mookie Ticket [3a24cc9df1]: 3 changes [History diff]2025-04-12 22:45:11
mookie Ticket [3a24cc9df1]: 4 changes [History diff]2025-04-12 22:45:50
mookie Ticket [3a24cc9df1]: 4 changes [History diff]2025-04-12 22:48:16
griffinplain2025-04-12 23:57:56
This behavior is expected. Tcl is not parsed like other programming languages. It is an organized collection of strings that can be evaluated to do things. 
Read this man page carefully. https://www.tcl-lang.org/man/tcl8.6/TclCmd/Tcl.htm 
It defines everything you need to know about Tcl. 

This is an over simplification: There is no “comment” in Tcl. Instead, commands that start with a # are ignored. 

I hope this helps.
mookieplain2025-04-28 14:19:16
Many Thanks.
pooryorick Ticket [3a24cc9df1]: 5 changes [History diff]2025-05-02 07:48:56
Log in (anonymous is fine) to add a comment.