| Ticket UUID: | 1106138 | ||
| Title: | Integer option to switch command | ||
| Type: | RFE | Created on: | 2005-01-20 17:26:11 |
| Submitter: | ruffrecords | Assigned to: | dkf |
| Subsystem: | 18. Commands M-Z | Severity: | |
| Priority: | 5 Medium | Last modified: | 2026-11-13 11:18:43 |
| Status: | Closed | Closed by: | serhiy.storchaka |
| Resolution: | Fixed | Closed on: | 2026-11-13 11:18:43 |
| Version: | None | ||
| Description: | ||||
I propose the addition of an option to the switch command to allow integer comparisons much like the switch statement in C. | ||||
| User Comments: | ||||
dkf added on 2005-01-21 15:56:19:
Logged In: YES
user_id=79902
Matter was discussed on c.l.t:
http://groups-beta.google.com/group/comp.lang.tcl/browse_frm/thread/a0b1398ff0b42638/66809fe88969cd04?_done=%2Fgroup%2Fcomp.lang.tcl%3Fhl%3Den%26&_doneTitle=Back+to+topics&_doneTitle=Back&&d#66809fe88969cd04
Idea is that this should work as (arithmetically) expected:
switch -integer [expr {int(sqrt(4))}] {
0x00 { puts "root 4 is zero" }
0x01 { puts "root 4 is one" }
0x02 { puts "root 4 is two" }
}
i.e. We want an option for [switch] to use ==-like equality
as well as eq-like equality. For the bytecode-compiled
version, this is almost trivial (add check-integer and use
INST_EQ instead of INST_STR_EQ) but it is a bit more work
for the non-BC version.
serhiy.storchaka added on 2026-11-13 11:18:43:
Implemented in Tcl 9.1 by TIP 730: switch -integer compares the value and the patterns as integers, so the example above matches 0x02. | ||||
