Version 3 of '--' in Tcl

Updated 2006-07-21 14:24:10

Several Tcl commands, including expect and switch, take a '--'. RS calls this, "the switch to end all switches". Here's why:

What is the difference between

    switch $variable {...

and

    switch -- $variable {...

? None--mostly; if, however, $variable contains a string such as "-glob", then the first form will be interpreted as

    switch -glob {...

Do you see the problem? Do you see how your datum might be interpreted as a command "switch"? In casual English words, the '--' says, "treat everything that follows like data, not as a 'switch' or 'flag' ..."

Alas, not every tcl command which takes a switch/flag recognizes -- as a valid entry. This means that the casual tcl programmer needs to check regularly to see if the command being coded accepts the -- or not. It surely would be nice if all tcl commands which take a -argument also accepted -- ...


Category Syntax