Posted to tcl by hypnotoad at Thu May 11 11:12:59 GMT 2017view raw
- oo::class create layout.compartment.5compt { method compartment_do trial {} }
- oo::class create layout.generator.one { method generator_do trial {} }
- oo::class create layout.generator.two { method generator_do trial {} }
- oo::class create layout.generator.three { method generator_do trial {} }
- oo::class create layout.switchboard.one { method switchboard_do trial {} }
- oo::class create layout.switchboard.two { method switchboard_do trial {} }
- oo::class create layout.switchboard.three { method switchboard_do trial {} }
- oo::class create builder {
- method build {trial combo} {
- set classes {}
- foreach {f v} $combo {
- lappend classes layout.$f.$v
- }
- oo::objdefine [self] mixin {*}$classes
- foreach f [dict keys $combo] {
- my ${f}_do $trial
- }
- }
- }
- proc permutation {combinations body {valuevar values} {values {}} {level 0}} {
- incr level
- set final 1
- foreach {field valuelist} $combinations {
- if {[dict exists $values $field]} continue
- set final 0
- if {[llength $valuelist]==0} {
- dict set values $field {}
- permutation $combinations $body $valuevar $values $level
- } else {
- foreach value $valuelist {
- dict set values $field $value
- permutation $combinations $body $valuevar $values $level
- }
- }
- return
- }
- uplevel $level [list set $valuevar $values]
- uplevel $level [list dict with $valuevar {}]
- uplevel $level $body
- }
- set trial 0
- builder create ITERATOR
- permutation {
- compartment {5compt}
- generator {one two three}
- switchboard {one two three}
- } {
- ITERATOR build [incr trial] $combo
- puts "Trial $trial $combo"
- } combo