Version 1 of ranged switch

Updated 2005-12-19 01:52:59

coyotes rand mair fheal wrote in the comp.lang.tcl newsgroup:

 proc rangedswitch {index switches} {
     for {set i 0} {$i<[llength $switches]} {incr i} {
         if {[string equal $switches([expr {$i+1}]) ..]} {
             set match [expr {$switches($i)<=$index &&$index<=$switches([expr {$i+2}])}]
             incr i 2
         } else {
             set match [expr {$switches($i)==$index}]
         }
    et cetera

    rangedswitch $i {
        0 {do a}
        2 .. 5 {do b}
    }

* Could someone elaborate on this? It won't work as-is. -- Sy / jrandomhacker.info