I’m working on the resistor color problem but in the requirements there are:
- to look up the numerical value associated with a particular color band
- to list the different band colors
but in the code for test there are other’s like for bl*, for example.
I’m begginer in tcl and I’m not a developer professional my view is very basic for example:
namespace eval resistorColor {
proc colorCode {color} {
set color [string tolower $color]
switch $color {
black { return 0 }
brown { return 1 }
red { return 2 }
orange { return 3 }
yellow { return 4 }
green { return 5 }
blue { return 6 }
violet { return 7 }
grey { return 8 }
white { return 9}
default {
error “Unknown color”
}
}
}proc colors {} { return [list black brown red orange yellow green blue violet grey white ] }
}
resistorColor::colors
foreach col [list black brown red orange yellow green blue violet grey white beige bl* ] {
resistorColor::colorCode $col
}
I see other solutions with a array, I belief, but I have to explore them next.